JSON响应返回数字,而不是实际数据

时间:2015-07-03 18:07:31

标签: ios json swift alamofire

我正在开发一款与Shopify API交互的快速应用。当我在浏览器中查看API端点时,我会看到实际数据。每当我使用Swift发出相同的请求(使用Alamofire发出HTTP请求)时,只返回一系列数字,如下所示:

  7b226375 73746f6d 5f636f6c 6c656374 696f6e73 223a5b7b 22626f64 795f6874 6d6c223a 22222c22 68616e64 6c65223a 22616363 6573736f 72696573 222c2269 64223a34 37303136 30322c22 7075626c 69736865 645f6174 223a2232 3031332d 31312d30 38543135 3a32393a 30302d30 383a3030 222c2270 75626c69 73686564 5f73636f 7065223a 22676c6f 62616c22 2c22736f 72745f6f 72646572 223a226d 616e7561 6c222c22 74656d70 6c617465 5f737566 66697822 3a22222c 22746974 6c65223a 22416363 6573736f 72696573 222c2275 70646174 65645f61 74223a22 32303135 2d30372d 30335430 383a3332 3a30332d 30373a30 30227d2c 7b22626f 64795f68 746d6c22 3a22222c 2268616e 646c6522 3a226265 616e6965 73222c22 6964223a 31313238 39383331 2c227075 626c6973 6865645f 6174223a 22323031 332d3131 2d303854 31353a32 343a3030 2d30383a 3030222c 22707562 6c697368 65645f73 636f7065 223a2267 6c6f6261 6c222c22 736f7274 5f6f7264 6572223a 226d616e 75616c22 2c227465 6d706c61 74655f73 75666669 78223a22 222c2274

此端点上的数据在浏览器中如下所示:

{"custom_collections":[{"body_html":"","handle":"accessories","id":4701602,"published_at":"2013-11-08T15:29:00-08:00","published_scope":"global","sort_order":"manual","template_suffix":"","title":"Accessories","updated_at":"2015-07-03T08:32:03-07:00"},

2 个答案:

答案 0 :(得分:1)

根据README:从Alamofire获取JSON数据,使用responseJSON方法:

Alamofire.request(...)
         .responseJSON() { request, response, jsonData, error in
              println("json data: \(jsonData)")
         }

答案 1 :(得分:0)

“一系列数字”是JSON字符串

的NSData(字节)表示
7b is {
22 is "
63 is c

你可以使用NSJSONSerialization将其转换为Dictionary / Array结构或NSString(data:NSData)来获取字符串表示

相关问题