ios - 我需要在 ios 的键中不带双引号的 json 字符串

标签 ios json

我把json串上传到服务端就好

 NSDictionary *values = [[NSDictionary alloc]initWithObjectsAndKeys:@"name", @"objective", nil];
 NSArray *array = [[NSArray alloc]initWithObjects:values,nil];
 NSDictionary *result = [[NSDictionary alloc]initWithObjectsAndKeys:array, @"objectives", nil];

我使用以下代码将字典转换为 JSON:

id obj = result;
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:obj options:kNilOptions error:&error];
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

我得到了正确的 json,例如

{ "objectives":[
     {"objective":"name"}
]
}

这是正确的 json 但我需要类似 json 的字符串

 { objectives:[
     {"objective":"name"}]
}

是否可以在 iOS 中创建不带双引号的键

只有这个 json 字符串我们才能得到响应,否则我会得到错误。

最佳答案

如果它只是您要从中删除引号的第一个键,您可以使用以下快速解决方法

jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\"objectives\"" withString:@"objectives"]];

关于ios - 我需要在 ios 的键中不带双引号的 json 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26817932/

相关文章:

objective-c - Xcode iOS 界面生成器

iOS:一个完整​​的 360 度旋转使用 block ,而不是 CABasicAnimation

ios - 我如何在 ios swift 3.0 中禁用 ytplayer 中的 youtube Logo

javascript - 如何在 AngularJS 中发出 http 请求以获取 JSON 数据格式?

android - 读取 SharedPreferences 中的自定义 ArrayList 调用运行时异常

Python搜索替换为多个Json对象

arrays - 为什么 JSON 返回这样的值 2.2348142859517371e-314 和 6.9531204333502763e-310

c++ - OpenCV 透视校正和裁剪

json - 使用 Jersey 在 REST Web 服务中返回 JSON 时,找不到媒体类型 = application/json 的 MessageBodyWriter

iphone - 你能用 Ruby 开发原生 iPhone 应用程序吗?