Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone上的JSON数据问题_Iphone_Objective C_Ios - Fatal编程技术网

iPhone上的JSON数据问题

iPhone上的JSON数据问题,iphone,objective-c,ios,Iphone,Objective C,Ios,我从JSON web服务获取这些数据 [{"identity":"DEMO","assets":[{"identity":"34DL3611","systemId":"544507"},{"identity":"34GF0512","systemId":"5290211"},{"identity":"34HH1734","systemId":"111463609"},{"identity":"34HH1736","systemId":"111463622"},{"identity":"34YCJ

我从JSON web服务获取这些数据

[{"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”,“系统ID”:“544507”}):

vehicleList=[dict objectForKey:@“资产”];
self.listVehicles=[[NSMutableArray alloc]init];
对于(整数索引=0;索引<[vehicleList count];索引++){
itemDict=[车辆列表对象索引:索引];
[self.listVehicles addObject:[itemDict objectForKey:@“identity”];
}
如何获取systemId值

我已经为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"]];
}
vehicleListID=[dict objectForKey:@“systemId]”;
self.listVehiclesID=[[NSMutableArray alloc]init];
对于(整数索引=0;索引<[vehicleListID计数];索引++){
assetsIdDict=[vehicleListID对象索引:索引];
[self.listVehiclesID addObject:[assetsIdDict objectForKey:@“systemId]”;
}

但获取错误:[uuuu NSCFNumber count]:无法识别的选择器发送到实例0x784c730

您基本上就快到了。您可能只是想要这样:

NSString *systemId = [itemDict objectForKey:@"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"]];
}

然后对所有这些对象执行任何操作。

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

    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"]];

}

要在单独的数组中使用,需要初始化新的NSMutableArray并添加对象


否则,更好的方法是,声明一个包含2个NSString成员的新类,例如,
identity
systemId
。从JSON中提取值并分配给类成员。然后将该对象添加到数组中。

同样的方法。
[itemDict objectForKey:@“systemId”]
。要在数组中进行此操作,您需要初始化新的NSMUTABLEARRY。我尝试了此操作,但给出了错误:[\uu NSCFNumber count]:发送到实例0x784c730的无法识别的选择器
NSNumber *outerIdentity = [dict objectForKey:@"identity"];
NSNumber *outerSystemId = [dict objectForKey:@"systemId"];
NSArray *vehicleList = [dict objectForKey:@"assets"];
for (NSUInteger index = 0; index < [vehicleList count]; index++) {
    NSDictionary *itemDict = [vehicleList objectAtIndex: index];
    NSString *identity = [itemDict objectForKey:@"identity"];
    NSString *systemId = [itemDict objectForKey:@"systemId"];
}
    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"]];

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