所以我有一个返回此JSON的Web服务:
[{"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]
感谢任何帮助,我不知道在哪里查看/调试
答案 0 :(得分:1)
尝试以下方法:
SBJSON *parser = [[SBJSON alloc] init];
NSString *responseString = [request responseString];
NSError *jsonError=nil;
NSArray *responseArray = [parser objectWithString: responseString error: &jsonError];
if (jsonError==nil) {
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);
}
}
祝你好运
吨