我是iPhone新手。我从服务器接收一些数据然后如何在JSON中解析数据。在这里,我想要解析JSON后所有人的名字。以下是我从服务器接收数据的可能性如何?
{ "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"
}
}
答案 0 :(得分:0)
您需要为Objective-C使用JSON解析库。我建议JSON Framework。 (现在它被称为SBJson)它被广泛使用。我们一直在几个项目中使用它,但没有任何问题。
答案 1 :(得分:0)
-(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"]];
}
}
}
答案 2 :(得分:0)
我是JSONKit的粉丝。它实现起来要小得多(只有.h和.m文件)并且非常快速和高效。 SBJson也很好,但是大多数人不需要很多开销。 (流,写作等)。
NSDictionary *myData = [jsonString objectFromJSONString];
NSString *name = [myData objectForKey:@"data"] objectForKey:@"name"];
NSArray *names = [myData objectForKey:@"data"]; // save all names into an array
答案 3 :(得分:0)
iOS 5版本中包含JSON的API函数。 检查API文档中的NSJSONSerialization。
e.g:
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData: data options: kNilOptions error: error];
答案 4 :(得分:0)
首先你应该添加Json框架。获取字典变量来加载json的响应。因为字典格式的数据。然后在一个数组中找到一个数组并加载该字典。然后将值存储到对象中,最后得到值