Iphone json框架EOF错误


Iphone JSON-Framework EOF Error

我试图使用json框架解析输出(在iPhone上)从我的网站。网站上的数据是一组新闻对象。通过PHP的json_encode().

JSON输出在这里:http://pastebin.com/Be429nHx

我能够连接到服务器并存储JSON数据,然后我做:

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"]);
我从NSLog()行收到以下错误:
-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)

任何帮助都将非常感激……谢谢! !

这可能是因为JSON的结构是一个数组,所以你应该这样做:

NSArray *items = [jsonString JSONValue];
NSLog(@" NewsID : %@", [[items objectAtIndex:1] objectForKey:@"newsID"]);

或者,也可以将JSON本身更改为:

{"somekeyname":[your existing json array]}