NSData和JSON的问题

时间:2016-01-25 03:59:09

标签: json swift

我有一个通过网络从API加载JSON的应用程序。在通常的数据集下,它可以正常工作,我在返回之前的调试代码将打印我的JSON内容。但是,对于一个特定的数据集,JSON内容为空,我无法弄清楚原因。以下是我的网络课程的相关代码,以及它令人窒息的数据集。

    // prepare the NSURL and other request parts
    let requestUrl = NSURL(string:escapedUrlString!)
    let req = NSURLRequest(URL: requestUrl!)
    let res:AutoreleasingUnsafeMutablePointer<NSURLResponse?> = nil

    // send the request; get a response
    let responseData = try? NSURLConnection.sendSynchronousRequest(req, returningResponse: res) as NSData!

    let finalResponseJSON = JSON(data: responseData!)
    print(finalResponseJSON)
    return finalResponseJSON

JSON:

{
  "success": true,
  "message": "",
  "displayname": "",
  "username": "",
  "avaurl": "",
  "location": "",
  "bio": "",
  "followers": 0,
  "following": 0,
  "blocked": false,
  "statusid": 0,
  "statuses": [
    {
      "id": 2356,
      "username": "grogov",
      "success": true,
      "failmessage": "",
      "author": "grogov",
      "authoravatar": "http://i.imgur.com/0gaAKHB.jpg",
      "content": "'Snowboarding with the NYPD': YouTube filmmakers use NYC blizzard kills 24, Washington struggles to rebound",
      "group": "Public",
      "time": "2016-01-25T00:38:00.053"
    },
    {
      "id": 2355,
      "username": "grogov",
      "success": true,
      "failmessage": "",
      "author": "grogov",
      "authoravatar": "http://i.imgur.com/0gaAKHB.jpg",
      "content": "It’s not just Flint residents still paying bills for viral video",
      "group": "Public",
      "time": "2016-01-24T21:33:50.25"
    },
    {
      "id": 2354,
      "username": "grogov",
      "success": true,
      "failmessage": "",
      "author": "grogov",
      "authoravatar": "http://i.imgur.com/0gaAKHB.jpg",
      "content": "Amid confusion, officials clarify ID 'request' in Flint residents still paying bills for viral video",
      "group": "Public",
      "time": "2016-01-24T21:30:14.237"
    },
    {
      "id": 2353,
      "username": "grogov",
      "success": true,
      "failmessage": "",
      "author": "grogov",
      "authoravatar": "http://i.imgur.com/0gaAKHB.jpg",
      "content": "Flint residents still paying bills for viral video",
      "group": "Public",
      "time": "2016-01-24T21:26:25.47"
    },
    {
      "id": 2352,
      "username": "grogov",
      "success": true,
      "failmessage": "",
      "author": "grogov",
      "authoravatar": "http://i.imgur.com/0gaAKHB.jpg",
      "content": "'Snowboarding with the NYPD': YouTube filmmakers use NYC blizzard shutdown for contaminated water",
      "group": "Public",
      "time": "2016-01-24T21:26:07.97"
    }
  ],
  "users": null,
  "groups": null,
  "trends": null
}

0 个答案:

没有答案