{
"id": "1",
"result": [
{
"Name": "John",
"Statu": "Online"
},
{
"Name": "Alex",
"Statu": "Online"
},
{
"Name": "Diaz",
"Statu": "Offline"
}
]
}
How do i extract each “car” JSON object and put it into a native object? I tried several way but i can’t do that.
NSString *responseString = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
NSString *responseDict = [responseString JSONValue];
NSArray *objects = [NSArray arrayWithObjects:[responseDict valueForKeyPath:@"result.Name"],[responseDict valueForKeyPath:@"result.Statu"],nil];
NSLog(@"objects Array: %@",objects);
**==> NSLOG gives:
(
(
"John",
"Alex",
"Diaz"
),
(
"Online",
"Online",
"Offline"
)
)
NSArray *resultsArray = [responseString JSONValue];
for (NSDictionary *personDict in resultsArray)
{
NSLog(@"ihaleAdi =: %@",[carDict valueForKey:@"result.ihaleAdi"]);
NSLog(@"ihaleDurum =: %@",[carDict valueForKey:@"result.Statu"]);
}
But ıt gıves an error tooç I want to just lıst them but ı cant do thatç can anybody help me please? thank you for reading
Use an Array to capture the responseString:
Then when you need an individual item from that array use a Dictionary:
Given a JSON responseString that looks like this:
[{“UniqueID”:111111,”DeviceName”:”DeviceName1″,”Location”:”Device1Loc”,”Description”:”Device1Desc”},{“UniqueID”:22222,”DeviceName”:”DeviceName2″,”Location”:”Device2Loc”,”Description”:”Device2Desc”}]
You will wind up with an Array that looks like this:
And a Dictionary of index 0 that looks like this:
Sorry for any confusion and improperly instantiated object earlier. I am still a relative newbie that learned something today.