【发布时间】:2012-02-23 04:01:35
【问题描述】:
所以我有一个返回这个 JSON 的网络服务:
[{"other_user":"54","distance":"1 ft","duration":"1 min"},{"other_user":"55","distance":"2 ft","duration":"5 min"}]
然后在我的 ios 应用中使用:
NSString *responseString = [request responseString];
NSArray *responseArray = [responseString JSONValue];
for (NSDictionary* item in responseArray) {
NSString *otherUser = [item objectForKey:@"other_user"];
NSString *otherDistance = [item objectForKey:@"distance"];
NSString *otherDuration = [item objectForKey:@"duration"];
NSLog(@"user: %@ distance: %@ time: %@", otherUser, otherDistance, otherDuration);
}
但我收到此错误:
-JSONValue failed. Error is: Illegal start of token [S]
感谢任何帮助,我不知道在哪里查看/调试
【问题讨论】:
-
验证您的 JSON 响应 (jsonlint.com) 以查看它是否是有效的 JSON 对象。您使用哪个 JSON Parser 来解析项目中的 JSON 响应?
-
我正在使用 SBJSON,它是有效的
-
打印出
responseString。我猜这不是有效的 JSON。 -
你说得对,我有一些回声。我现在觉得很傻。很抱歉浪费了您的时间。