Json parsing returned by foursquare for iPhone gives unrecognized lead character

I am trying to find nearby places using api. Here is the json data that is returned from

NSDictionary *results = [jsonString JSONValue]; NSLog(@"%@", results); ( { code = 200; errorDetail = "This endpoint will stop returning groups in the future. Please use a current version, see http://bit.ly/lZx3NU."; errorType = deprecated; }, { groups = ( { items = ( { categories = ( { icon = "https://foursquare.com/img/categories/parks_outdoors/default.png"; id = 4bf58dd8d48988d163941735; name = Park; parents = ( "Great Outdoors" ); pluralName = Parks; primary = 1; shortName = Park; } ); 

Then I try to get a list of groups in an array with

 NSArray *groups = [ (NSDictionary *)results objectForKey:@"groups"]; 

This returns the following error

 2011-11-05 11:42:12.907 XperienzApp[1972:207] No of results returned: 0 Results : (null) 2011-11-05 11:42:13.225 XperienzApp[1972:207] -JSONValue failed. Error trace is: ( "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Unrecognised leading character\" UserInfo=0x5849cd0 {NSLocalizedDescription=Unrecognised leading character}" ) 2011-11-05 11:42:13.225 XperienzApp[1972:207] No of results returned: 0 Results : (null) 

How can I make it out?

Edit: I tried the suggested technique, this gives me an array

 id groups = [[(NSDictionary *)results objectForKey:@"response"] objectForKey:@"groups"]; if ([results count] > 1){ NSLog(@"groups class %@\ngroups %@ %d", groups, [groups class], [groups count]); 

The output of the log is:

  { categories = ( { icon = "https://foursquare.com/img/categories/nightlife/danceparty.png"; id = 4bf58dd8d48988d11f941735; name = Nightclub; parents = ( "Nightlife Spots" ); pluralName = Nightclubs; primary = 1; shortName = Nightclub; } ); contact = { }; hereNow = { count = 0; }; id = 4eb33ba561af0dda8f673c1b; location = { address = "144 Willow St 4R"; city = Brooklyn; crossStreet = Pierrepont; distance = 462; lat = "40.696864"; lng = "-73.996409"; postalCode = 11201; state = NY; }; name = "Entertainment 720, Ltd."; stats = { checkinsCount = 3; tipCount = 0; usersCount = 1; }; verified = 0; } ); name = Nearby; type = nearby; } ) groups __NSArrayM 1 

This is not json again and it is hard to figure out how I can get the result in json.

+4
source share
2 answers

I head the iPhone four times. I will try to take a hit what's going on here.

First of all, I highly recommend using JSONKit for your parser. It is lightweight and insanely fast: https://github.com/johnezang/JSONKit

It looks like you are parsing JSON correctly and getting the dictionary correctly. Then you register the parsed object, not the original JSON. You see how Objective-C chooses serialization of parsing in the text. This is definitely not JSON. Using JSONKit, you can send the JSONString selector to the result of the analysis and convert it back to JSON and register it.

If you could provide some information about the problem you are trying to solve, I could help you more. And as Modicus said, pay attention to the error you are returning. You do not want your application to crash when we make changes to the API.

+3
source

If the result is lower than NSLog(@"%@", results); - This is your journal operator. It seems your result variable is an array of dictionary objects.

Try writing a result class to make sure NSLog(@"%@", [results class]);

If it is an array, then your group object is the second object.

 if ([results count] > 1) id groups = [results objectAtIndex:1]; NSLog(@"groups class %@\ngroups %@", [groups class], groups); 

Continue to do this until you understand the format of your data.

Also string

 errorDetail = "This endpoint will stop returning groups in the future. Please use a current version, see http://bit.ly/lZx3NU."; 

should be troubling. Check the four-level documentation for the current way to get groups.

+1
source

Source: https://habr.com/ru/post/1379751/


All Articles