Iphone JSON-Framework EOF Error
I'm attempting to use Json-Framework to parse output (on the iPhone) from my website. The data on the website is an array of news objects... passed through PHP's json_encode().
The JSON Output is here: http://pastebin.com/Be429nHx
I am able to connect to the server and store the JSON data, the开发者_如何转开发n I do:
NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
// Create a dictionary from the JSON string
NSDictionary *results = [jsonString JSONValue];
NSArray *items = [results valueForKeyPath:@"data.array"];
NSLog(@" NewsID : %@", [[items objectAtIndex:1] objectForKey:@"newsID"]);
and I receive the following error from the NSLog() line:
-JSONValue failed. Error is: Didn't find full object before EOF
Event Id : (null)
STATE: <SBJsonStreamParserStateStart: 0x4e3c960>
JSONValue failed. Error is: Token 'key-value separator' not expected before outer-most array or object
Event Id : (null)
Any help will be greatly appreciated... thanks!!!
It might be because your JSON is structured as an array, so you should just do:
NSArray *items = [jsonString JSONValue];
NSLog(@" NewsID : %@", [[items objectAtIndex:1] objectForKey:@"newsID"]);
or, alternately, change the JSON itself so that it's more like:
{"somekeyname":[your existing json array]}
精彩评论