Sunday, 15 January 2012

JSON parsing in iOS 6 issues -


I'm trying to parse some values ​​from a JSN. I manage to get value for results.geometry.location. If the benchmark fails then the server returns a Jason with the value 2. The result which is empty [] and the condition "some error"

  url = [NSString stringWithFormat:. @ "Http://maps.googleapis.com/maps/api/geocode/json?address =% @ & amp; sensor = false", PostalCode]; NSData * jsonDataString = [[NSString stringWithContentsOfURL: [NSURL URLWithString: URL] Encoding: NSUTF8StringEncoding error: zero] dataUsingEncoding: NSUTF8StringEncoding]; NSArray * myResults = [NSJSONSerialization JSONObjectWithData: jsonDataString options: NSJSONReadingMutableContainers | NSJSONReadingMutable saves error: & amp; Error]; LatLon = [myResults valueForKeyPath: @ "results.geometry.location"]; GeneralDict = (NSDictionary *) [latLon ObjectTime: 0]; NSLog (@ "% @", [GenDist Object Faroeque: @ "Lieutte"]);   

I tried it confusing:

  latLon = [myResults valueForKeyPath: @ ""]; GeneralDict = (NSDictionary *) [latLon ObjectTime: 0]; NSLog (@ "% @", [General Deck Object Farcie: @ "Status"]);   

But I'm not working How do I get the value of the situation? [:

  { "result"], "status": "ZERO_RESULTS"}    that it is invalid how when requested look 

myResults is a dictionary, not an array. I think you have something like this:

  NSURL * url = [NSURL urlWithString: [NSString stringWithFormat: @ "http://maps.googleapis.com/maps/api/geocode/ Addressed to json? =% @ & Amp; sensor = false ", PostalCode]; NSURLRequest * Request = [NSURL request request with url: url]; [NSURLConnection sendAsynchronousRequest: Request line: [NSOperationQueue mainQueue] completionHandler: ^ (NSURLResponse * reaction, NSData * data, NSError * error) {NSDictionary * jsonPayload = [NSJSONSerialization JSONObjectWithData: data base: NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves Error: Zero]; NSString * Position = [jsonPayload objectForKey: @ "status"]; // Check for error status NSArray * resultsArray = [jsonPayload objectForKey: @ "result"]; // whatever you want with your result array}};    

No comments:

Post a Comment