相关疑难解决方法(0)

Objective-C JSON - 将JSON对象转换为本机对象?

{"status": "FRE", "list": [{"make": "Toyota", "id": 1, "model": "camry", "engine": "Four Cylinder"}{"make": "Ford", "id": 3, "model": "focus", "engine": "Four Cylinder"}]}
Run Code Online (Sandbox Code Playgroud)

如何提取每个" car" JSON object并将其放入原生object?我正在使用SBJSON.这是我当前的代码,但它只能提取一个car元素,当我需要能够迭代每个car对象并保存它:

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];
Run Code Online (Sandbox Code Playgroud)

iphone json objective-c ios

0
推荐指数
1
解决办法
1万
查看次数

标签 统计

ios ×1

iphone ×1

json ×1

objective-c ×1