我是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"
我有四个数组:
completedarray
orderarray [0] = 146
totalarray [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我怎么能再次显示内部数组两个字典呢?
我想显示姓名" :" Bleach"," name" :"正常"在基于索引路径的单个tableview单元格中,如categoryarray [0]
如何在单个字符串plz中获取这两个名称给我一些想法..
感谢。
答案 0 :(得分:0)
您需要循环catergoryarray
并获取每个字典。然后,您可以从字典中获取单个值。
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)
然后,您可以根据需要使用该信息填充表格单元格。显然,您需要修改名称的连接方式以满足您的需求。
希望有所帮助。