下面是位於json.txt內容如何從這種結構中獲取數據,JSONKit
{
"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')。 – Hejazi 2012-08-14 21:32:12