我是 iOS 开发新手,任何人都可以给我一些 swift 的想法吗?解析后我有 JSON 数据,我将数据存储在数组中,如示例所示。
"orderId" : 146,
"total" : 2,
"created_at" : "2016-09-19 11:08:51",
"categories" : [
{
"name" : "Bleach",
"qrCode" : "SRY-001-0098",
"weight" : 1,
"categoryId" : "57dbd9ca8e1a0919c9075d13",
"amount" : 1
},
{
"name" : "Normal (26+ lbs)",
"qrCode" : "SRY-001-0099",
"weight" : 1,
"categoryId" : "57dbd9708e1a094ecb10cfb1",
"amount" : 1
}
],
"completed_at" : "2016-09-19 00:00:00"
我有四个数组:
- 顺序数组
- 总数组
- 创建数组
- 类别数组
完成数组
顺序数组[0] = 146
总数组[0] = 2
createatarrays[0] = "2016-09-19 11:08:51"
cartegoriesarray[0] =
[ { "name" : "Bleach", "qrCode" : "SRY-001-0098", "weight" : 1, "categoryId" : "57dbd9ca8e1a0919c9075d13", "amount" : 1 }, { "name" : "Normal", "qrCode" : "SRY-001-0099", "weight" : 1, "categoryId" : "57dbd9708e1a094ecb10cfb1", "amount" : 1 } ]
completedarray[0] = "2016-09-19 00:00:00"
使用indexpathrow,我可以根据 TableView 单元格中的索引路径显示orderarray、totalarray、createdarray。
但是这里的categoryarray如何在数组中再次显示两个字典?
我想根据像categoryarray[0]这样的索引路径在单个表格 View 单元格中显示 name": "Bleach", "name": "Normal"
如何在单个字符串中获取这两个名称,请给我一些想法..
谢谢。
最佳答案
您需要循环categoryarray
并取出每个字典。然后您可以从字典中获取各个值。
var name = "";
//Loop the array of dictionaries
for dict in categoryarray as! NSDictionary {
//extract the items from the dictionary. and concatenate names
name = name + " " + dict["name"];
}
print("Name: ", name)
然后,您可以使用该信息根据需要填充表格单元格。显然,您需要修改名称的连接方式以满足您的需要。
希望有帮助。
关于ios - 如何在 swift ios 的单个 uitableviewcell 中显示多个字典或数组数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39576159/