来自NSArray的Group TableView项在Swift中的JSON响应中返回

时间:2016-02-20 05:52:03

标签: ios arrays swift uitableview

我有一个表格视图,我希望使用JSON形式的NSArray响应中提供给我的值填充表格视图,并使用下面的代码提取此{ {1}}:

NSArray

在JSON响应中,我得到以下两个元素的数组,如下所示:

dispatch_async(dispatch_get_main_queue(), {
                        print(json)
                        if let listDictionary = parseJSON["list"] as? NSArray {
                            print("LIST: \(listDictionary)")
                        }
})

现在我想将数组中每个元素的值“name”,“price”和“remark”字段显示为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"; } );

但我无法找到一种方法来破坏每个元素的名称,价格和备注的值,并将它们放入另一个数组中,以便它们可以以某种方式显示在表视图中,因为每个元素都包含一个非常长的字符串,我只需要从这个字符串中提取一些值。任何人都可以帮助我,因为我对Swift很新。

谢谢!

2 个答案:

答案 0 :(得分:0)

您不需要创建第二个数组,只需从Template.launcherBody.helpers({ workspace: function () { return Workspace.find({ "member_id": Meteor.userId()}); }, boards: function () { /*return Board.find({"workspaceId": ??? }) */ } }); 中的数组中通过cellForRowatIndexPath数组方法从数组中取出特定的json,现在就可以访问了。

答案 1 :(得分:0)

  • 您可以通过创建仅包含的模型类来实现它 你需要的那些属性。
  • 从服务器获取响应数组后,逐个迭代 字典并创建一个Model Object.Add中的这个模型对象 阵列。
  • 使用数组中的此模型对象,使用索引
  • 在单元格中应用数据
  
      
  • 要添加的另一件事总是更喜欢使用对象,因为它提供了(。)点语法&自我暗示,所以会有更少的机会   犯错误。好像你使用字典会有更多的机会   使用不正确的密钥崩溃
  •