help me to parse JSON value using JSONTouch
Posted
by
EquinoX
on Stack Overflow
See other posts from Stack Overflow
or by EquinoX
Published on 2011-01-29T07:06:11Z
Indexed on
2011/01/29
7:25 UTC
Read the original article
Hit count: 175
iphone
|objective-c
I have the following json:
http://www.adityaherlambang.me/webservice.php?user=2&num=10&format=json
I would like to get all the name in this data by the following code, but it gives an error. How can I fix it?
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSDictionary *results = [responseString JSONValue];
NSDictionary *users = [results objectForKey:@"users"] objectForKey:@"user"];
for (NSDictionary *user in users){
//NSLog(@"key:%@, value:%@", user, [user objectForKey:user]);
NSString *title = [users objectForKey:@"NAME"];
NSLog(@"%@", title);
}
Error:
2011-01-29 00:18:50.386 NeighborMe[7763:207] -[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0xb618840
2011-01-29 00:18:50.388 NeighborMe[7763:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0xb618840'
*** Call stack at first throw:
(
0 CoreFoundation 0x027d9b99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0292940e objc_exception_throw + 47
2 CoreFoundation 0x027db6ab -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x0274b2b6 ___forwarding___ + 966
4 CoreFoundation 0x0274ae72 _CF_forwarding_prep_0 + 50
5 NeighborMe 0x0000bd75 -[NeighborListViewController connectionDidFinishLoading:] + 226
6 Foundation 0x0007cb96 -[NSURLConnection(NSURLConnectionReallyInternal) sendDidFinishLoading] + 108
7 Foundation 0x0007caef _NSURLConnectionDidFinishLoading + 133
8 CFNetwork 0x02d8d72f _ZN19URLConnectionClient23_clientDidFinishLoadingEPNS_26ClientConnectionEventQueueE + 285
9 CFNetwork 0x02e58fcf _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 389
10 CFNetwork 0x02e5944b _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 1537
11 CFNetwork 0x02d82968 _ZN19URLConnectionClient13processEventsEv + 100
12 CFNetwork 0x02d827e5 _ZN17MultiplexerSource7performEv + 251
13 CoreFoundation 0x027bafaf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
14 CoreFoundation 0x0271939b __CFRunLoopDoSources0 + 571
15 CoreFoundation 0x02718896 __CFRunLoopRun + 470
16 CoreFoundation 0x02718350 CFRunLoopRunSpecific + 208
17 CoreFoundation 0x02718271 CFRunLoopRunInMode + 97
18 GraphicsServices 0x030b800c GSEventRunModal + 217
19 GraphicsServices 0x030b80d1 GSEventRun + 115
20 UIKit 0x002e9af2 UIApplicationMain + 1160
21 NeighborMe 0x00001c34 main + 102
22 NeighborMe 0x00001bc5 start + 53
23 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
I really just wanted to be able to iterate through the names
© Stack Overflow or respective owner