【问题标题】:how to sort my json data and load uitable view swift3?如何对我的 json 数据进行排序并加载 uitableview swift 3?
【发布时间】:2018-04-13 05:39:45
【问题描述】:

如何加载我的 json 数据并加载合适的视图我尝试了很多时间但没有找到结果。这是我的 json 树

[
  {
    "id": 1,
    "name": "Leanne Graham",
    "username": "Bret",
    "email": "Sincere@april.biz",
    "address": {
      "street": "Kulas Light",
      "suite": "Apt. 556",
      "city": "Gwenborough",
      "zipcode": "92998-3874",
      "geo": {
        "lat": "-37.3159",
        "lng": "81.1496"
      }
    },
    "phone": "1-770-736-8031 x56442",
    "website": "hildegard.org",
    "company": {
      "name": "Romaguera-Crona",
      "catchPhrase": "Multi-layered client-server neural-net",
      "bs": "harness real-time e-markets"
    }
  },

]

有人帮帮我吗?谢谢提前

【问题讨论】:

  • 你试过的显示你的代码!
  • 显示你的代码需要做什么

标签: arrays json swift xcode


【解决方案1】:

将代码 json 转换为数组,然后尝试此代码。

  let sortedArray = sortArrayUsingKey(strKey: "id", unSortedArray:unsortarray)

 func sortArrayUsingKey(strKey:String,unSortedArray:NSArray) ->NSArray {

    var tempArray:NSMutableArray = NSMutableArray();
    tempArray = unSortedArray.mutableCopy() as! NSMutableArray;
    let descriptor = NSSortDescriptor(key: strKey, ascending: true);
    tempArray.sort(using: [descriptor]);
    return tempArray as NSArray;
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多