+ (NSString *)UIUtilsFomateJsonWithDictionary:(NSDictionary *)dic {
NSArray *keys = [dic allKeys];
NSString *string = [NSString string];
for (NSString *key in keys) {
NSString *value = [dic objectForKey:key];
value = [NSString stringWithFormat:@"\"%@\"",value];
NSString *newkey = [NSString stringWithFormat:@"\"%@\"",key];
if (!string.length) {
string = [NSString stringWithFormat:@"%@:%@}",newkey,value];
}else {
string = [NSString stringWithFormat:@"%@:%@,%@",newkey,value,string];
}
}
string = [NSString stringWithFormat:@"{%@",string];
return string;
}
+ (NSString *)UIUtilsFomateJsonArrWithArray:(NSArray *)array {
NSString *string = [NSString string];
for (int j = 0; j<array.count; j++) {
NSDictionary *dic = array[j];
NSArray *keys = [dic allKeys];
for (int i = 0; i<keys.count; i++) {
NSString *key = keys[i];
NSString *value = [dic objectForKey:key];
value = [NSString stringWithFormat:@"\"%@\"",value];
key = [NSString stringWithFormat:@"\"%@\"",key];
if (!string.length) {
string = [NSString stringWithFormat:@"%@:%@}",key,value];
}else if(i == 0){
string = [NSString stringWithFormat:@"%@:%@}%@",key,value,string];
}else {
string = [NSString stringWithFormat:@"%@:%@,%@",key,value,string];
}
}
if (j != array.count-1) {
string = [NSString stringWithFormat:@",{%@",string];
}else {
string = [NSString stringWithFormat:@"[{%@]",string];
}
}
return string;
} |
|