JSON数据问题iPhone [英] JSON data issue iPhone

查看:27
本文介绍了JSON数据问题iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从JSON Web服务获取此数据

I am getting this data from JSON web services

[{"identity":"DEMO","assets":[{"identity":"34DL3611","systemId":"544507"},{"identity":"34GF0512","systemId":"5290211"},{"identity":"34HH1734","systemId":"111463609"},{"identity":"34HH1736","systemId":"111463622"},{"identity":"34YCJ15","systemId":"294151155"}],"systemId":4921244}]

我正在使用此方法获取身份资产的值(资产":[{身份":"34DL3611","systemId":"544507"}):

I am using this method to get the values of assets for identity ("assets":[{"identity":"34DL3611","systemId":"544507"}):

 vehicleList = [dict objectForKey: @"assets"];

    self.listVehicles = [[NSMutableArray alloc] init];

for (NSUInteger index = 0; index < [vehicleList count]; index++) {

    itemDict = [vehicleList objectAtIndex: index];

    [self.listVehicles addObject:[itemDict objectForKey:@"identity"]];
}

如何获取systemId值...?

how can I get the systemId values ... ?

我已经尝试过使用systemId

I have tried this for systemId

vehicleListID = [dict objectForKey:@"systemId"];

    self.listVehiclesID =[[NSMutableArray alloc]init];

for (NSUInteger index = 0; index < [vehicleListID count]; index++) {

    assetsIdDict = [vehicleListID objectAtIndex: index];

    [self.listVehiclesID addObject:[assetsIdDict objectForKey:@"systemId"]];
}

但出现错误:[__NSCFNumber count]:无法识别的选择器已发送到实例0x784c730

but getting error: [__NSCFNumber count]: unrecognized selector sent to instance 0x784c730

推荐答案

您得到的json响应是一个数组.vehicleList应该是json响应的objectatIndex 0.

The json response you are getting is an array. vehicleList should be the objectatIndex 0 of json response.

    NSDictionary  *vehicleList = [[arrayLoadedFromJson objectAtIndex:0] objectForKey: @"assets"];


vehicleList = [dict objectForKey: @"assets"];

    self.listVehicles = [[NSMutableArray alloc] init];

for (NSUInteger index = 0; index < [vehicleList count]; index++) {

    itemDict = [vehicleList objectAtIndex: index];

    [self.listVehicles addObject:[itemDict objectForKey:@"identity"]];

    [self.listVehicles addObject:[itemDict objectForKey:@"systemId"]];

}

您必须在代码中插入:-

This you have to insert:-in your code

  [self.listVehicles addObject:[itemDict objectForKey:@"systemId"]];

这篇关于JSON数据问题iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆