如何将 json 数组分配给单元格字符串?
How can I assign json array into cell string?
我有如下示例 json 数据,我想将这些数据分配到我的单元格列表中。目前我的结果将错误地显示在属性名称中。:-
{
"attribute_group_name" = Color;
"attribute_name" = (
Black,
White,
Gold,
Red
);
},
{
"attribute_group_name" = Service;
"attribute_name" = (
"Free Shipping",
Insurance
);
},
{
"attribute_group_name" = Telco;
"attribute_name" = (
Digi,
Maxis,
Celcom
);
},
{
"attribute_group_name" = Material;
"attribute_name" = (
Wood
);
},
{
"attribute_group_name" = Brand;
"attribute_name" = (
Apple,
Mi,
Gome,
HuaWei
);
},
这是我当前的输出。我的列表中有错误的属性名称(重复数据),但 header 是正确的。
这是我在 cellForItemAtIndexPath 和 numberOfItemsInSection 中的代码。感谢您的帮助:-
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
FilterItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:FilterItemCellID forIndexPath:indexPath];
//HOW to set cell.attribute_name here?
NSLog(@"1 - %@",(NSArray *)[self.filterItem[indexPath.section] valueForKey:@"attribute_name"]);
// Result in 1 - (
// Black,
// White,
// Gold,
// Red
// )
// How can I set it accordingly in cell?
return cell;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return ((NSArray *)[self.filterItem[section] valueForKey:@"attribute_name"]).count;
}
cell.attribute_name=[[self.filterItem[section] valueForKey:@"attribute_name"]objectAtIndex:indexPath.row];
我有如下示例 json 数据,我想将这些数据分配到我的单元格列表中。目前我的结果将错误地显示在属性名称中。:-
{
"attribute_group_name" = Color;
"attribute_name" = (
Black,
White,
Gold,
Red
);
},
{
"attribute_group_name" = Service;
"attribute_name" = (
"Free Shipping",
Insurance
);
},
{
"attribute_group_name" = Telco;
"attribute_name" = (
Digi,
Maxis,
Celcom
);
},
{
"attribute_group_name" = Material;
"attribute_name" = (
Wood
);
},
{
"attribute_group_name" = Brand;
"attribute_name" = (
Apple,
Mi,
Gome,
HuaWei
);
},
这是我当前的输出。我的列表中有错误的属性名称(重复数据),但 header 是正确的。
这是我在 cellForItemAtIndexPath 和 numberOfItemsInSection 中的代码。感谢您的帮助:-
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
FilterItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:FilterItemCellID forIndexPath:indexPath];
//HOW to set cell.attribute_name here?
NSLog(@"1 - %@",(NSArray *)[self.filterItem[indexPath.section] valueForKey:@"attribute_name"]);
// Result in 1 - (
// Black,
// White,
// Gold,
// Red
// )
// How can I set it accordingly in cell?
return cell;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return ((NSArray *)[self.filterItem[section] valueForKey:@"attribute_name"]).count;
}
cell.attribute_name=[[self.filterItem[section] valueForKey:@"attribute_name"]objectAtIndex:indexPath.row];