【发布时间】:2012-08-14 21:25:18
【问题描述】:
以下是位于 json.txt 的内容
{
"data": [
{
"keyId": 3,
"title": "This is a fundraiser 1",
"budget": "1000",
"users": {
"user": [
{
"id": "3",
"first_name": "A1",
"last_name": "A11",
"is_owner": "false"
},
{
"id": "2",
"first_name": "B1",
"last_name": "B11",
"is_owner": "true"
}
]
}
}
]
}
为了得到idKey 和title 和budget 我正在做的是
@implementation Account
@synthesize arr;
-(void)parse {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"fundraiser_json" ofType:@"txt"];
NSString *jsonString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
NSDictionary *dict = [jsonString objectFromJSONString];
self.arr = [dict objectForKey:@"data"];
for ( NSDictionary *acc in self.arr ) {
Account *account = [[Account alloc] init];
[account setKeyID: [acc objectForKey:@"keyId"]];
[account setTitle: [acc objectForKey:@"title"]];
[account setBudget: [acc objectForKey:@"budget"]];
}
}
然后我尝试访问users 并获取其中每个user 的一些信息,但我不能
谁能帮助我如何访问和获取这些数据。
【问题讨论】:
-
您是否假设
users是一个数组?它不在上面给定的 JSON 中,它是一个对象 (NSDictionary)。