How to parse the data in json

I am new to iPhone. I am receiving some data from the server then how can that data can be parsed in JSON. Here I want the name of all the people after parse the JSON. How it is possible the below one is my receiving data from the server?

{   "data":
    [{      "name":"Ashresh Devisetti","id":"1018103475"
    },{     "name":"Atluri Suhas","id":"1033093758"
    },{     "name":"Tejaswi Kumar","id":"1119007960"
    },{     "name":"Vineel MSatian","id":"1126218004"
    },{     "name":"Somesh Nookala","id":"1135608183"
    },{     "name":"Sriram Poduri","id":"1153984821"
    },{     "name":"Somesh Nookala","id":"1279615172"
    },{     "name":"Ravi Kanth","id":"1392429155"
    },{     "name":"Manikanta Swaroop","id":"1625515823"
    },{     "name":"Amulya Marivada","id":"1704204546"
    },{     "name":"Naresh Kumar Geddam","id":"1739192069"
    },{     "name":"Chaitanya Chaitu","id":"1749870844"
    },{     "name":"Cheruku Swamy","id":"1791647314"
    },{     "name":"Ramya Naidu","id":"1848155470"
    },{     "name":"Sri Divya Chenna","id":"100000032711858"
    },{     "name":"Sandeepkumar Katakam","id":"100000045911895"
    },{     "name":"Rupendra Kumar M","id":"100000050422004"
    },{     "name":"Sruthi Gollapudi","id":"100000055991847"
    },{     "name":"Ramanamurthy Saripalli","id":"100000073436389"
    },{     "name":"Ravi Teja","id":"100000085284134"
    },{     "name":"Sasank Pisipati","id":"100000183890281"
    },{     "name":"Sneha Yadla","id":"100000266481511"
    },{     "name":"Teja Bhupatiraju","id":"100000267197072"
    },{     "name":"Anisha Kosuri","id":"100000389025595"
    },{     "name":"Arun Kumar","id":"100000389565527"
    },{     "name":"Rohini Krishna","id":"100000545110674"
    },{     "name":"Lalitha Satyavolu","id":"100000545503024"
    },{     "name":"Ralli Raghu","id":"100000548726955"
    },{     "name":"Mansoor Sha","id":"100000560237166"
    },{     "name":"Tarun Medisetti","id":"100000612310803"
    },{     "name":"Anand Sathivada","id":"100000636872860"
    },{     "name":"Siva Prasad Rayapudi","id":"100000684818891"
    },{     "name":"Surekha Koruprolu","id":"100000704491702"
    },{     "name":"Sam Ernesto","id":"100000722715489"
    },{     "name":"Kalyan Kuchipudi","id":"100000764050697"
    },{     "name":"Sai Sandeep","id":"100000775011879"
    },{     "name":"Uma Kethavarapu","id":"100000777379251"
    },{     "name":"Lokesh Varma","id":"100000862073560"
    },{     "name":"Anusha Prakash","id":"100000916534219"
    },{     "name":"Tendu Chandu","id":"100001021718095"
    },{     "name":"Surendra Varma","id":"100001030129883"
    },{     "name":"Shiv Charan Yedavalli","id":"100001104018801"
    },{     "name":"Surya Sri Avinash","id":"100001261348651"
    },{     "name":"Sandeep Choppala","id":"100001381957897"
    },{     "name":"Sandeep Vaitla","id":"100001440817792"
    },{     "name":"Aadi Narayana","id":"100001453941516"
    },{     "name":"Brahmani Achanta","id":"100001526798068"
    },{     "name":"Prasad Pothala","id":"100001531038570"
    },{     "name":"Harsha Vardhan G","id":"100001547227974"
    },{     "name":"Satish Chowdary","id":"100001553950656"
    },{     "name":"Pramod Dsrb","id":"100001579793628"
    },{     "name":"Sree Ram","id":"100001582161546"
    },{     "name":"Ratnadeepthi Allakki","id":"100001607126997"
    },{     "name":"Bobba Satish Kumar","id":"100001623868422"
    },{     "name":"Sudheera Indugula","id":"100001628983788"
    },{     "name":"Phani Allada","id":"100001665690488"
    },{     "name":"Naveen Kumar","id":"100001695204621"
    },{     "name":"Akula Sundar Kumar","id":"100001722776059"
    },{     "name":"Karthik Varma Pakalapati","id":"100001754077975"
    },{     "name":"Sriram Valluri","id":"100001766246694"
    },{     "name":"Ramya Sindhuri","id":"100001839785670"
    },{     "name":"Rajendra Rudra","id":"100001877367454"
    },{     "name":"Anusha Kola","id":"100001927730228"
    },{     "name":"Gowtham Raj Chilakapati","id":"100001968713154"
    },{     "name":"Prasad Durga","id":"100002082589163"
    },{     "name":"Padmini Sudheera Tatiraju","id":"100002101582586"
    },{     "name":"Murali Nadh","id":"100002150494601"
    },{     "name":"Harish Harshu","id":"100002153956398"
    },{     "name":"Naveen Kumar","id":"100002223484093"
    },{     "name":"Satish Kumar","id":"100002241855098"
    },{     "name":"Siva Kumar","id":"100002316574080"
    },{     "name":"Harish Kalidindi","id":"100002350209493"
    },{     "name":"Ram Babu Yadamareddy","id":"100002350852565"
    },{     "name":"Aruna Sree","id":"100002394713943"
    },{     "name":"Siva Prasad","id":"100002396785204"
    },{     "name":"Navya Prasanna","id":"100002419100201"
    },{     "name":"Ramireddy Paila","id":"100002552254549"
    },{     "name":"John Edward","id":"100002595557538"
    },{     "name":"Abhishek Namma","id":"100002641337357"
    },{     "name":"Tirumala Rayudu Tandra","id":"100002673802695"
    },{     "name":"Lakshmiviveka Goli","id":"100002820242067"
    },{     "name":"Durgarao Vasamsetti","id":"100002947094683"
    },{     "name":"Geda Sudheer","id":"100002968743878"
    },{     "name":"Krishna Prasad Pasupuleti","id":"100003027388345"
    },{     "name":"Sudheer Palatherthapu","id":"100003095500995"
    },{     "name":"Raja Ramesh Haddubangi","id":"100003098069539"
    },{     "name":"Rupa Kamireddy","id":"100003137137936"
    },{     "name":"Krishnarao Paruchuri","id":"100003337821817"
    },{     "name":"Teja Varma","id":"100003786723963"
    },{     "name":"Madhuri Jasti","id":"100003926095705"
    }],"paging":{       "next":"https:\/\/graph.facebook.com\/100003137741947\/friends?value=1&redirect=1&access_token=AAAB3DjBNjrEBACF2foZBM6qModwfmyOP24zMBK6skwxN31aA3oLxTCuu2KI9CgnvAJu4yUxDFK9KyKnrErrv2q5zee4U5VcSbyoeDTAZDZD&limit=5000&offset=5000&__after_id=100003926095705"
    }
}

Answers


You need to use a JSON parsing library for Objective-C. I would recommend JSON Framework. (now it's called SBJson) It's widely used. We've been using it on several projects with success and no issues at all.


-(void)getData:(NSData*)response{

 // You have to include the SBJSON or else you can also use the NSJSONSerialization

 //NSDictionary *jsonData          =           [NSJSONSerialization JSONObjectWithData:response options:kNilOptions error:&erro];

SBJSON *parse                               =           [[SBJSON alloc]init];

NSString *jsonString                        =           [[NSString alloc] initWithData:response
                                                                            encoding:NSUTF8StringEncoding]; 

NSDictionary *jsonData                      =           [parse objectWithString:jsonString error:&erro];

NSArray *alldata                          =           [jsonData objectForKey:@"data"];

if(![alldata isKindOfClass:[NSNull class]] && [alldata count] > 0)
{
    for(int i = 0; i < [alldata count]; i++)
    {
        NSDictionary *getData               =       [allEvents objectAtIndex:i];

        NSString *nameString                   =       [NSString stringWithFormat:@"%@",[getData objectForKey:@"name"]];

         NSString *idString                   =       [NSString stringWithFormat:@"%@",[getData objectForKey:@"id"]];

    }

}

}

I'm a big fan of JSONKit. It is a lot smaller to implement (just a .h and .m file) and is very fast and efficient. SBJson is also good, but has a lot of overhead most people don't need. (stream, writing, etc).

NSDictionary *myData = [jsonString objectFromJSONString];

NSString *name = [myData objectForKey:@"data"] objectForKey:@"name"];
NSArray *names = [myData objectForKey:@"data"]; // save all names into an array

There are API functions for JSON included with the iOS 5 release. Check NSJSONSerialization in the API documentation.

e.g.:

NSDictionary *dict =  [NSJSONSerialization JSONObjectWithData: data options: kNilOptions error: error];

first you should add Json framework. take a dictionary variable to load the response of json. because data in dictionary format. then in that an array is located so take an array and load that dictionary. then store the values to the object finally you got the values


Need Your Help

Static Class Variables in Dynamic Library and Main Program

c++ shared-libraries glibc static-variables dlopen

I am working on a project that has a class 'A' that contains a static stl container class. This class is included in both my main program and a .so file. The class uses the default(implicit, not

Multithread without tightly coupled objects

java multithreading swing

I'm trying to build a simple game in Java. Ran into the problem of the JTextPanel not updating until after the game loop terminates, which of course, isn't a good experience for the player.