所以我有一个web服务,它返回这个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]
感谢您的帮助,我不知道在哪里查找/调试
尝试以下操作:
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);
}
}
好运
t