У меня есть следующие данные JSON, пытающиеся проанализировать в Objective C - мой код возвращает нулевые значения для значений объекта нижнего уровня - userid, FirstName и LastName
Полный JSON:
{
"members" :
[
{"member" : {"userid":"1","FirstName":"ramesh","LastName":"babu"}},
{"member" : {"userid":"2","FirstName":"ramesh2","LastName":"babu2"}},
{"member" : {"userid":"3","FirstName":"ramesh3","LastName":"babu3"}}
]
}
Мой код:
- (void)viewDidLoad
{
[super viewDidLoad];
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL: kLatestKivaLoansURL];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});
}
- (void)fetchedData:(NSData *)responseData {
//parse out the json data
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData //1
options:kNilOptions
error:&error];
NSArray* members = [json objectForKey:@"members"]; //2
NSString *text1 = [json description];
jsonSummary.text = text1;
NSEnumerator *e = [members objectEnumerator];
NSArray *keys = [NSArray arrayWithObjects:@"userid", @"FirstName", @"LastName", nil];
NSDictionary * member;
while (member = (NSDictionary *)[e nextObject]) {
// do something with object
// Iterate it
text1 = [member description];
NSLog(@"MEMBER ROW DATA%@", text1);
for (id key in keys) {
text1 = [member description];
NSLog(@"key: %@ value:%@ ", key, [member objectForKey:key]);
}
}
}
Любая помощь будет оценена !!