objective c - How to convert data string to json object and string in iOS? -


how convert string json object or json array in ios? json string that.

{"data": [{"id":"1","name":"raj"},{"id":"2","name":"rajneesh"}]} 

i want id or name string please me if this.

thank you.

i try below code print null

  nsstring *jsonstring=@"{"data": [{"id":"1","name":"raj"},{"id":"2","name":"rajneesh"}]}";     nsdata *objectdata = [jsonstring datausingencoding:nsutf8stringencoding];     nsdictionary *json = [nsjsonserialization jsonobjectwithdata:objectdata options:0 error:&error];     nsarray* array = [json objectforkey:@"data"];     nslog(@"print array %@",array); 

use this

nsstring *str=@"{\"data\": [{\"id\":\"1\",\"name\":\"raj\"},{\"id\":\"2\",\"name\":\"rajneesh\"}]}";  nsmutabledictionary *dict=[nsjsonserialization jsonobjectwithdata:[str datausingencoding:nsutf8stringencoding] options:kniloptions error:nil];  nsmutablearray *dataarr=[dict valueforkey:@"data"]; (nsdictionary *userdata in dataarr) {     nslog(@"id:%@ name:%@",[userdata valueforkey:@"id"],[userdata valueforkey:@"name"]); } 

Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -