{"status": "FRE", "list": [{"make": "Toyota", "id": 1, "model": "camry", "engine": "Four Cylinder"}{"make": "Ford", "id": 3, "model": "focus", "engine": "Four Cylinder"}]}
我如何提取每个“car
" JSON object
并将其放入本地object
?我在用着SBJSON http://stig.github.com/json-framework/api/3.0/。这是我当前的代码,但当我需要能够迭代每个汽车对象并保存它时,它只能提取一个汽车元素:
NSString *responseString = [request responseString];
NSString *responseDict = [responseString JSONValue];
NSArray *keys = [NSArray arrayWithObjects:@"id",@"make",@"model",@"engine", nil];
NSArray *objects = [NSArray arrayWithObjects:[responseDict valueForKeyPath:@"list.make"],[responseDict valueForKeyPath:@"list.model"],[responseDict valueForKeyPath:@"list.id"],[responseDict valueForKeyPath:@"list.engine"] , nil];
self.car = [[NSDictionary alloc]initWithObjects:objects forKeys:keys];
使用 Jastor,而不是手动完成所有操作 -https://github.com/elado/jastor https://github.com/elado/jastor您只需要创建简单的类并initWithDictionary
将为您完成整个分配工作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)