user831679
user831679

Reputation:

JSON parsing data iPhone

How can I parse this data to use it: I am getting below data using NSString and showing it on console through NSLog.

HTML = {"session":"2a1d9a1db71b443d7a9702816663d8d","role":"normal","account":"uid\[email protected],o\u003dDemo,o\u003dUnd"}

I want to get the values of accounts and then want to use them to select one of them for which I will use picker view.

and this data array:

Group = ["DEMO"]

Thanks

Upvotes: 0

Views: 206

Answers (2)

Manish Agrawal
Manish Agrawal

Reputation: 11026

you can take this html response in NSDictionary and then access it elements by using the following code

NSDictionary *html = [responseString JSONValue];
NSString * session = [html objectForKey:@"session"]//returns session id
NSString * role = [html objectForKey:@"role"]
NSString *accounts = [html objectForKey:@"account"]//This will get the accounts string with comma separated.
NSArray *accountList = [account componentsSeparatedByString:@","];//It will return the array of all acount values which you can use in picker view to select one

you can check this by checking the array size such that

if(accountList.count>1)
{
//contains multiple accounts
}
else (if(accountList.count == 1)
{
//only one account
}
else
{
//No account
}

Upvotes: 1

Ilanchezhian
Ilanchezhian

Reputation: 17478

Use JSONKit to parse the JSON data.

Include downloaded JSONKit files to your project. Import that .h file.

//HTML is your downloaded string JSON Feed
NSDictionary *deserializedData = [HTML objectFromJSONString];

//Helpful snippet to log all the deserialized objects and their keys
NSLog(@"%@", [deserializedData description]);

Upvotes: 1

Related Questions