ios - 难以在Objective C中处理json格式

标签 ios objective-c json

我需要从此数组转换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/

相关文章:

iphone - Xcode 5命令行:体系结构“arm64”的无效部署目标“3.0.0”

ios - 带有保管箱 URL 错误 : _itemFailedToPlayToEnd: 的 MPMoviePlayerViewController

iphone - 仅在一个 View 上更改导航栏

Javascript 在 for 循环中导航类

arrays - SSJS 从数组中删除项目

ios - 获取 AWSAccountID

objective-c - Facebook Connect Safari 无法打开页面

html - 如何更改 ios 中段落中的特定字符串?

ios - 如何以编程方式添加 ChildVC?

c++ - 将 OpenCV Mat 转换为数组(可能是 NSArray)