gpt4 book ai didi

iphone - 用于选择器 View iPhone 的 JSON 数组

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:00:02 24 4
gpt4 key购买 nike

我从 JSON 网络服务获取这些数据

List ARRAY: (
{
assets = (
{
identity = 34DL3611;
systemId = 544507;
},
{
identity = 34GF0512;
systemId = 5290211;
},
{
identity = 34HH1734;
systemId = 111463609;
},
{
identity = 34HH1736;
systemId = 111463622;
},
{
identity = 34YCJ15;
systemId = 294151155;
}
);
identity = DEMO;
systemId = 4921244;
})

通过使用此代码:

NSArray *list =[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];

NSLog(@"Response data: %@", responseString);

NSLog(@"List ARRAY: %@", list);

NSDictionary *dict = [list objectAtIndex: 0];

NSMutableArray *vehicleGroups = [dict objectForKey:@"identity"];

NSLog(@"Vehicle Groups: %@", vehicleGroups);

这是我正在使用的选择器代码:

    -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent :(NSInteger)component {
return [vehicleGroups count];}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{return nil;}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
}

应用程序在该行崩溃

return [vehicleGroups count];

pickerView 的委托(delegate)方法 numberOfRowsInComponent。我不明白 - 为什么我会遇到这个问题?

//代码////

    NSArray *list =[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];

NSLog(@"Response data: %@", responseString);

NSLog(@"List ARRAY: %@", list);

NSDictionary *dict = [list objectAtIndex: 0];

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

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

vehicleGroups = [dict objectForKey:@"identity"];

NSLog(@"Vehicle Groups: %@", vehicleGroups);

NSString *identity = [dict objectForKey: @"identity"];

NSString *systemid = [dict objectForKey:@"systemId"];

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

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

NSLog(@"GroupOfVehicles: %@", groupOfVehicles);

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

itemDict = [vehicleList objectAtIndex: index];

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

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

NSLog(@"Group Name: %@", identity);

NSLog(@"Assets: %@", listVehicles);

NSLog(@"Assets System ID: %@", listVehiclesID);

NSLog(@"GroupSystemID: %@", systemid);

最佳答案

你必须先初始化你的数组

NSDict *list =[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];

NSLog(@"List Dict: %@", list);

NSMutableArray *temp = list[@"assets"];
NSMutableArray *vehicleGroups = [NSMutableArry array];
vehicleGroups = temp[0][@"identity"];

NSLog(@"Vehicle Groups: %@", vehicleGroups);

关于iphone - 用于选择器 View iPhone 的 JSON 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8890808/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com