【发布时间】:2011-11-27 05:39:17
【问题描述】:
{"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。这是我当前的代码,但它只能提取一个汽车元素,当我需要能够遍历每个汽车对象并保存它时:
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];
【问题讨论】:
标签: iphone objective-c ios json