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"
}
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.