[英]JSON Parser doesn't get whole code
I am using the Foursquare API to get near places to the Users location. 我正在使用Foursquare API靠近用户位置。 A sample response for only one place is here .
这里仅提供一个示例响应。
Now when I parse the response using JSONkit, the parser "forgets" the first part. 现在,当我使用JSONkit解析响应时,解析器“忘记”了第一部分。 The data I get begins from the tag "canonicalUrl".
我得到的数据从标签“ canonicalUrl”开始。 But I need the first part of the response too.
但是我也需要响应的第一部分。 Iam using this code to parse the data:
Iam使用以下代码来解析数据:
-(void)getDataWithLongitude:(float)longitude andLatitude:(float)latitude {
// Get current date
NSDate *date = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"YYYYMMdd"];
NSString *dateString = [dateFormat stringFromDate:date];
NSString *theURL = [NSString stringWithFormat:@"https://api.foursquare.com/v2/venues/search?ll=40.7,-74&client_id=MY_ID&client_secret=MY_SECRET&v=%@&locale=de&limit=10&venuePhotos=1", dateString];
NSError *err = nil;
NSURLResponse *response = nil;
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSURL *url = [NSURL URLWithString:theURL];
[request setURL:url];
[request setCachePolicy:NSURLRequestReloadIgnoringCacheData];
[request setTimeoutInterval:30];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSDictionary *resultsDictionary = [data objectFromJSONData];
NSArray *array = [resultsDictionary valueForKeyPath:@"response.venues"];
NSLog(@"%@", array);
}
I used now NSJSONSerialization for the parsing but with no other result. 我现在使用NSJSONSerialization进行解析,但没有其他结果。
NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingMutableContainers error: &err];
As it turned out in the discussion, both JSONKit and NSJSONSerialization parse the FourSquare response correctly. 在讨论中发现,JSONKit和NSJSONSerialization都正确解析了FourSquare响应。
The only reason that some parts seemed to be missing is that the dictionary key/value pairs were displayed in a different order than in the JSON data. 某些部分似乎丢失的唯一原因是字典键/值对以与JSON数据不同的顺序显示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.