我需要从此数组转换json字符串
( {
1 = 4;
},
{
8 = 20;
})
其实我需要像
{"custom":{"1":"3","8":"21"}}
这样的输出,但是我得到了“{\n \"custom\" : \"[\\n {\\n \\\"1\\\" : \\\"4\\\"\\n },\\n {\\n \\\"8\\\" : \\\"20\\\"\\n }\\n]\"\n}"
这是我的代码
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:mydict options:NSJSONWritingPrettyPrinted error:&error];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
有什么办法可以得到这样的输出:
{"custom":{"1":"3","8":"21"}}
最佳答案
只需将NSJSONWritingPrettyPrinted
替换为0。
关于ios - 难以在Objective C中处理json格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45206047/