2016-06-25 117 views
0

我想從JSON中解析出「lat」和「lng」的值,然後將它解析爲目標C中的NSDictionary。如何解析它?解析嵌套的JSON到NSDictionary

html_attributions" : [], 
    "results" : [ 
     { 
     "geometry" : { 
      "location" : { 
       "lat" : 51.4994796, 
       "lng" : -0.1248094 
      } 
     }, 
     "id" : "f617d7c9e65e415fb39d4a0ae47dbb71f209d409", 
     "place_id" : "ChIJK0O8dMQEdkgRLApeea2WlHk", 
     "reference" : "CoQBcgAAAK8Oa0l7zRS1fqb83aJiHWadP3bh27CPVDILMBR7zA3CqEbR2pEro3O7sObQCoTIL7jP6bG_YL2-nCGzUlvIcyuG7HHrvCwakEjrbEImDp2VRkAbBbxUNz3V0mqUyFBFon_6G5pF_n4ovZ1fqaBhEPQ3lXbzGOJAwaOfhtKEda9mEhANy9NmIP8nHASNqiRIe-J_GhQR5WvFJnSbh23-30v2ScxAAuMT1Q" 
     }, 
     { 
     "geometry" : { 
      "location" : { 
       "lat" : 51.5058337, 
       "lng" : -0.1167623 
      } 
     }, 
     "id" : "ed60145ed3bbef5036f13fcdb67bae99ce970efd", 
     "place_id" : "ChIJT5N73bcEdkgRRRNgF3S7uwU", 
     "reference" : "CnRwAAAA_SvSiE9sjpnqkBCOWiScw4ih5qUGPbWrBG_mYmlJhZJVHREKsV9cVKXbS5iZZyQiebmdLzqPbH37itffgIwv8Dpucbk80BfPxmhMRPYDOC3HIzdho9ystp8wqEgUoGmRjIFDDzhDa0jY_sQTIfWtDhIQFhL6SKjC7K8nNbK8YqCZpRoU0Y0OWpDNfiCpzP8z-5bj2PJgEv8" 
     }, 

回答

1

見下

for(NSDictionary *dictionary in parentDictionary[@"results"]){ 
    NSDictionary *location=dictionary[@"geometry"][@"location"]; 
    NSLog(@"Lat = %f, Lng = %f",[location[@"lat"] floatValue],[location[@"lng"] floatValue]); 
} 

乾杯。

+0

感謝您的幫助:) –