json解析iphone sdk问题?
问题描述:
我有以下的json文件。json解析iphone sdk问题?
{
"id": "100001740605903",
"name": "Mike Watshan",
"first_name": "Mike",
"last_name": "Watshan",
"education": [
{
"school": {
"id": "21657666681",
"name": "University of Georgia"
},
"year": {
"id": "133832199985127",
"name": "2004"
},
"type": "College"
},
{
"school": {
"id": "106425642726879",
"name": "Valley High School"
},
"year": {
"id": "136656086362466",
"name": "2002"
},
"type": "High School"
}
],
"gender": "male",
"timezone": 5.5,
"locale": "en_US"
}
并使用下面的代码来解析json。
//jsonString is valid NSString object who contains valid json string.
//arrPro is NSArray object.
SBJSON *json = [[SBJSON new] autorelease];
self.arrPro = [json objectWithString:jsonString error:&error];
NSLog(@"stringObject %@",[[self.arrPro objectAtIndex:1] valueForKey:@"name"]);
,但得到的errer.Please帮助我....
答
你越来越对象中的NSDictionary,而不是NSArray中...
使用这个代替
SBJSON *json = [[SBJSON new] autorelease];
NSdictionary *dict = [json objectWithString:jsonString error:&error];
打印这本字典 里面的字典,你会发现数组 简单的json返回数组这里复杂的json返回字典
谢谢
你得到了什么样的错误? – 2011-02-15 07:13:19