ios - 使用 swiftyjson 从索引对象数组 ios 的 json 中检索标题

标签 ios json swift afnetworking swifty-json

JSON

    {
  "321" : {
    "title" : "xyz",
    "pageid" : 321,
    "ns" : 0
  },
  "172" : {
    "pageimage" : "xyzc.jpg",
    "pageid" : 172,
    "title" : "xyzcc",
    "ns" : 0,
    "thumbnail" : {
      "width" : 100,
      "height" : 57,
      "source" : "https:\/\/upload.abcd.org\/wikipedia\/commons\/thumb\/d\/de\/xyz.jpg\/100px-xyz.jpg"
    }
  },
  "224" : {
    "pageimage" : "abc.jpg",
    "pageid" : 224,
    "title" : "dasf",
    "ns" : 0,
    "thumbnail" : {
      "width" : 98,
      "height" : 100,
      "source" : "http:\/\/example.org\/images\/thumb\/2\/26\/skfdb.jpg\/98px-586px-dasdfsa.jpg"
    }
  },
  "825" : {
    "title" : "efkjdsb",
    "pageid" : 825,
    "ns" : 0
  },
  "229" : {
    "title" : "eafewg",
    "pageid" : 229,
    "ns" : 0
  }

使用 SwiftyJSON 从 JSONresponse 检索后,如何访问 JSON 文件中的“标题”和“缩略图”:“源”?

“321”、“172”可以改变并取决于。相同格式的数组中有多个对象。

有些对象有缩略图对象,有些则没有。

如何将 titlethumbnail->source 提取到带有图像和标签的 TableView 以创建列表。

(使用Swift语言) 我正在使用 AFNetworking

检索 json
let manager = AFHTTPSessionManager()
        manager.GET(url, parameters: nil, success: {(operation, responseObject) -> Void in

            let responsejson = JSON(responseObject!)


            print("\n \n \n \n \n \n  Retrieved = \n\(responsejson)")

            let items = responsejson.count
            print("Items : \(items)")

提前致谢。

最佳答案

您可以使用这样的代码来获取每个值:

for (key,obj) in responsejson {
    print(obj["title"])
    print(obj["thumbnail"]["source"])

}

关于ios - 使用 swiftyjson 从索引对象数组 ios 的 json 中检索标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41010029/

相关文章:

swift - 如何在 swift actor 中支持带超时的异步回调

xcode - swift 2 Spritekit : Issue with background music not resuming when the game is unpaused

iphone - 使用动画 block 移动原点调整 UIScrollView 的大小

ios - UINavigationController 的自定义 UIBarButtonItem/UISegmentedControl

json - 如何从既没有 CORS 也没有 JSONP 的源在网页上使用 JSON?

json - 带有命名空间的 XML 到 JSON

ios - 快速堆栈 View 中的表格 View

ios - 在 uitextfield 中输入文本时或之后使用退格键显示文本长度错误

iphone - 如何呈现登录工作流程? (模态和导航 Controller )

Python - json 中的 `\n`