A.sonu A.sonu - 6 months ago 27
JSON Question

json pattern display in iOS

I am having json pattern like this

output = (
{
id = {
php = 1;
};
image = {
1 = "http://www.easyteach.gr/users/tutor/1432636961.jpg";
};
name = {
php = ramkumar;
};
},
{
id = {
android = 1;
};
image = {
3 = "http://www.easyteach.gr/users/tutor/1432636961.jpg";
};
name = {
android = Vijayan;
};
},


I want to display
output->name->php
and
output->name->android
both in the same array.

This is my code:

nameArray = [json valueForKeyPath:@"output.name"];
NSLog(@"%@",nameArray);

Answer

You can do something like this,

NSArray *output; //your output array got from server

NSDictionary *dict = [output objectAtIndex:0];

NSDictionary *dict2 = [dict objectForKey:@"name"];

NSString *str = [dict2 objectForKey:@"php"];

same for android, you can use objectAtIndex : 1 instead 0

And make sure your response at android = Vijayan; or php = ramkumar; if it is wrong.

hope this will help :)

Comments