Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I parse this nested JSON output in Objective C?
    primarykey
    data
    text
    <p>I'm trying to parse a nested JSON output like this in Objective C:</p> <pre><code>{ -Status: { code: 200 request: "geocode" name: "1.304044,103.833867" } -Placemark: [ -{ -Point: { -coordinates: [ 103.834 1.30396 0 ] } -AddressDetails: { -Country: { CountryName: "Singapore" -Thoroughfare: { ThoroughfareName: "Bus stop at Lucky Plaza (09048)" } CountryNameCode: "SG" } Accuracy: 9 } id: "p1" address: "Bus stop at Lucky Plaza (09048)" } -{ -Point: { -coordinates: [ 103.834 1.30444 0 ] } -AddressDetails: { -Country: { CountryName: "Singapore" AddressLine: "Lucky Plaza" -Thoroughfare: { -PostalCode: { PostalCodeNumber: "238863" } ThoroughfareName: "304 Orchard Road" } CountryNameCode: "SG" } Accuracy: 9 } id: "p2" address: "Lucky Plaza, 304 Orchard Road, Singapore 238863" } -{ -Point: { -coordinates: [ 103.833 1.30376 0 ] } -AddressDetails: { -Country: { CountryName: "Singapore" AddressLine: "Wisma Atria" -Thoroughfare: { -PostalCode: { PostalCodeNumber: "238877" } ThoroughfareName: "435 Orchard Road" } CountryNameCode: "SG" } Accuracy: 9 } id: "p3" address: "Wisma Atria, 435 Orchard Road, Singapore 238877" } -{ -Point: { -coordinates: [ 103.835 1.30389 0 ] } -AddressDetails: { -Country: { CountryName: "Singapore" -Thoroughfare: { -PostalCode: { PostalCodeNumber: "238860" } ThoroughfareName: "291 Orchard Road" } CountryNameCode: "SG" } Accuracy: 9 } id: "p4" address: "291 Orchard Road, Singapore 238860" } -{ -Point: { -coordinates: [ 103.834 1.30491 0 ] } -AddressDetails: { -Country: { CountryName: "Singapore" AddressLine: "Kimsia Park" -Thoroughfare: { -PostalCode: { PostalCodeNumber: "228968" } ThoroughfareName: "1 Jalan Kayu Manis" } CountryNameCode: "SG" } Accuracy: 9 } id: "p5" address: "Kimsia Park, 1 Jalan Kayu Manis, Singapore 228968" } ] } </code></pre> <p>I have some code working, but I'm finding the nested nature of this to be pretty tough to figure out. What I'd like to get out is an array/dictionary which contains the following elements for each return record: coordinates, CountryName, ThoroughfareName, PostalCode and Accuracy.</p> <p>Here is my test code so far:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; NSURL *jsonURL = [NSURL URLWithString:@"http://gothere.sg/maps/geo?output=json&amp;ll=1.304044%2C103.833867&amp;client=&amp;sensor=false&amp;callback="]; NSString *jsonData = [[NSString alloc] initWithContentsOfURL:jsonURL]; self.jsonArray = [jsonData JSONValue]; NSLog(@"%@", jsonArray); [jsonURL release]; [jsonData release]; } </code></pre> <p>My code just manages to get the raw JSON output, any thoughts/code to break it down as I've mentioned above.</p> <p>Thanks!</p> <p>As requested, some further information.</p> <ol> <li>Using SBJson framework.</li> <li><p>NSLog output from above:</p> <pre><code>2011-08-30 16:44:32.605 Taxi[53070:207] { Placemark = ( { AddressDetails = { Accuracy = 9; Country = { CountryName = Singapore; CountryNameCode = SG; Thoroughfare = { ThoroughfareName = "Bus stop at Lucky Plaza (09048)"; }; }; }; Point = { coordinates = ( "103.834", "1.30396", 0 ); }; address = "Bus stop at Lucky Plaza (09048)"; id = p1; }, { AddressDetails = { Accuracy = 9; Country = { AddressLine = "Lucky Plaza"; CountryName = Singapore; CountryNameCode = SG; Thoroughfare = { PostalCode = { PostalCodeNumber = 238863; }; ThoroughfareName = "304 Orchard Road"; }; }; }; Point = { coordinates = ( "103.834", "1.30444", 0 ); }; address = "Lucky Plaza, 304 Orchard Road, Singapore 238863"; id = p2; }, { AddressDetails = { Accuracy = 9; Country = { AddressLine = "Wisma Atria"; CountryName = Singapore; CountryNameCode = SG; Thoroughfare = { PostalCode = { PostalCodeNumber = 238877; }; ThoroughfareName = "435 Orchard Road"; }; }; }; Point = { coordinates = ( "103.833", "1.30376", 0 ); }; address = "Wisma Atria, 435 Orchard Road, Singapore 238877"; id = p3; }, { AddressDetails = { Accuracy = 9; Country = { CountryName = Singapore; CountryNameCode = SG; Thoroughfare = { PostalCode = { PostalCodeNumber = 238860; }; ThoroughfareName = "291 Orchard Road"; }; }; }; Point = { coordinates = ( "103.83499999999999", "1.30389", 0 ); }; address = "291 Orchard Road, Singapore 238860"; id = p4; }, { AddressDetails = { Accuracy = 9; Country = { AddressLine = "Kimsia Park"; CountryName = Singapore; CountryNameCode = SG; Thoroughfare = { PostalCode = { PostalCodeNumber = 228968; }; ThoroughfareName = "1 Jalan Kayu Manis"; }; }; }; Point = { coordinates = ( "103.834", "1.30491", 0 ); }; address = "Kimsia Park, 1 Jalan Kayu Manis, Singapore 228968"; id = p5; } ); Status = { code = 200; name = "1.304044,103.833867"; request = geocode; }; </code></pre> <p>}</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload