[英]iphone with sbjson framework cant parse json array
我面临着json和目标c的一些问题。 Atm我正在使用sbJson框架(如果有人告诉我,我可以更改框架!),而且我无法解析json数组。
这是我要解析的json,
{"JsonEventosResult":
[
{"nombre":"Venta de Reposición N°13","id":34,"fecha":"16/09/2011"},
{"nombre":"evento rose","id":37,"fecha":"04/10/2011"},
{"nombre":"Prueba PhoneGap","id":40,"fecha":"23/11/2011"}
]
}
这是我在iPhone上的代码:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
NSError *error;
SBJSON *json = [[SBJSON new] autorelease];
NSArray *luckyNumbers = [json objectWithString:responseString error:&error];
[responseString release];
if (luckyNumbers == nil)
label.text = [NSString stringWithFormat:@"JSON parsing failed: %@", [error localizedDescription]];
else {
NSMutableString *text = [NSMutableString stringWithString:@"Lucky numbers:\n"];
for (int i = 0; i < [luckyNumbers count]; i++)
[text appendFormat:@"%@\n", [luckyNumbers objectAtIndex:i]];
label.text = text;
}
}
我得到的错误是luckyNumbers是一个包含0个对象的数组。
我从http://mobileorchard.com/tutorial-json-over-http-on-the-iphone/获得的示例。
那么问题出在哪里呢? 我得到表单服务或框架的json吗?
谢谢
您处理错误。 它不是数组,而是字典,键@“ JsonEventosResult”的值是数组。 因此,在您的JSON objectwithstring行中,将其设为nsdictionary,然后指向该键
或删除{“ JsonEventosResult”:和final},使其已经是数组
哦,我认为您必须Unicode转义带重音符号和度数的符号(在jsonlint.org上测试JSON以确保其有效)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.