1

Can anyone help me parse this complex nested json data?

I am working with iPhone Xcode 4.3 and objective-c.please provide small demo.

{"html_attributions" : [],
   "results" : [

      {
         "geometry" : {
            "location" : {
               "lat" : 61.1820430,
               "lng" : -149.8003850
            }
         },
         "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
         "id" : "207c77fb1258ef8cb22abe391c4924850a1ac045",
         "name" : "Alaska Native Medical Center Rad",
         "reference" : "CoQBdwAAAG5xNU-hb4BzNd-9H8IcLHcnz8txVe2j00HjRmjInS6uYt0j4qnAhOU_FNkHSSjvZd47dVu8Vk8Vj2iuu0NDDDa3tkCK-yHbUaj1Wrg5DNFvPmou1jvsjUE6gRKUAHXXemRJTNgtDfvhnS5kNdS0c71r9Df2S_Yvu0m92z62D0TZEhACm7dSGWKcpfZ_H-zTi5BzGhRCM22q0rCD6vjD3keZfBELfn_VsA",
         "types" : [ "hospital", "health", "establishment" ],
         "vicinity" : "4315 Diplomacy Drive, Anchorage"
      }
   ],
   "status" : "OK"
}
1
  • What language you are using to decode it? Commented Oct 19, 2011 at 5:37

4 Answers 4

1

For this kind of complex JSON string you can not use google's JSON frame work.But to assign that string to NSDictionary you will require that frame work. So first add that framework to your project.Then Add JSON.h file to your .m file. And then use assign that string as follows: NSDictionary *dic = [jsonString JSONValues]; After this line you will get all the values of your string in three keys. First key is "html_attributions" second key is "result" and third key is "status". For accessing the inner values of your second key you have to assign that to another NSDictionary or NSArray variable.And use key to access the values.

It will work for only above mentioned JSON String.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi stark....thanks for help it's work but i like to tell you something that i don't need to pass "html_attributions" as key.We can directly use result as key and it's work fine.Thanks Again.
If it was helpful then please give the ratings.
1

There's an objective-c library called JSONKit that works pretty well. It'll give you an NSArray or NSDictionary that you can then get your data out of.

https://github.com/johnezang/JSONKit

Its as easy as doing this:

NSDictionary *unserializedData = [jsonString objectFromJSONString];

where jsonString is your json data from above that you want to parse in an NSString.

Comments

0

Why don't you use a framework for that job?

You can try json-framework (formerly SBJSon).

Project page : https://github.com/stig/json-framework

Comments

0

If your on the iPhone you can use various JSON Libraries to turn JSON strings into NSDictionary and NSArray objects

JSON Kit is a very fast and lightweight library that you can use: https://github.com/johnezang/JSONKit

Or there is JSON-framework: http://code.google.com/p/json-framework/

Also if targeting iOS 5 devices, Apple has included their own JSON deserializer. Take a look at the NSJSONSerialization class

https://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.