我有以下 JSON 数据:
[{"id":"value","first_name":"value","last_name":"value"},
{"id":"value","first_name":"value","last_name":"value"},
{"id":"value","first_name":"","last_name":""}]
然后我实现我的代码:
NSError *err;
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://abcd.com/index.php?r=WS/Employee"]];
NSData *dataFromUrl = [NSData dataWithContentsOfURL:url];
NSMutableArray *array = [NSJSONSerialization JSONObjectWithData:dataFromUrl options: NSJSONReadingMutableContainers error:&err];
if (err)
NSLog(@"JSONObjectWithData error: %@", err);
为此,我收到以下错误消息:
JSONObjectWithData error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x9c900f0 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
请帮我获取这些数据。
最佳答案
我认为你应该在请求 header 中添加更多内容。尝试将 NSData 转换为 NSString,然后看看会发生什么
关于ios - 在 iOS 上解析 json 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25281241/