我有一个 TableView ,我想用 JSON
响应中以 NSArray
形式提供给我的值填充 TableView ,并且我使用了下面的代码用于提取此 NSArray
:
dispatch_async(dispatch_get_main_queue(), {
print(json)
if let listDictionary = parseJSON["list"] as? NSArray {
print("LIST: \(listDictionary)")
}
})
在 JSON 响应中,我得到以下两个元素的数组,如下所示:
list = (
{
"is_cover" = 0;
"is_recommand" = 0;
name = "Helena's Signature Dish";
ord = 5;
price = "105.00";
remark = "Helena's special made dish is one of the most priced and delicious dishes in the whole world.";
thumb = "56c351887a0e0.jpg";
},
{
"is_cover" = 0;
"is_recommand" = 0;
name = "Pineapple Fried Rice";
ord = 6;
price = "110.00";
remark = "We have the most delicious pineapple rice in the whole world!";
thumb = "56c704e15da79.jpg";
}
);
现在我想将数组中每个元素的值“name”、“price”和“remark”字段显示到 UITableView
中。
但是我找不到一种方法来打破每个元素的名称、价格和备注的值,并将它们放入另一个数组中,以便它们可以以某种方式显示在 TableView 中,因为每个元素都包含一个非常长的字符串,并且我只需要从这个字符串中提取一些值。谁能帮我解决这个问题,因为我对 Swift 很陌生。
谢谢!
最佳答案
您不需要创建第二个数组,只需通过数组的 objectatindex
方法从字典上的 cellForRowatIndexPath
数组中提取特定的 json,现在就可以访问了。
关于ios - 将 NSArray 中的 TableView 项目分组到 Swift 中的 JSON 响应中返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35519713/