如何在swift中的AFNetworking中获取正确的JSON文本

时间:2015-12-21 12:18:46

标签: ios json

我使用AFNetworking发出GET请求。我得到的结果不是JSON字符串,但它应该是一个JSON字符串。

我想获得以下JSON文本:

{
  "code": 200,
  "message": "success",
  "data": [
    {
      "goods_id": "31",
      "goods_item": "DA55098",
      "goods_price": "0",
      "goods_shop_price": "198",
      "class_id": "45",
      "goods_thumbnail_image": "/public/upload/goods/20151122/thumb_fcd13f057fa51d2d72826f7e26625b7c.jpg",
      "goods_name": "Product name",
      "buy_num": 0,
      "faverite_num": "0"
    }
  ]
}

但我得到了这个:

{
    code = 200;
    data =     (
                {
            "buy_num" = 0;
            "class_id" = 45;
            "faverite_num" = 0;
            "goods_id" = 31;
            "goods_item" = DA55098;
            "goods_name" = "Product name";
            "goods_price" = 0;
            "goods_shop_price" = 198;
            "goods_thumbnail_image" = "/public/upload/goods/20151122/thumb_fcd13f057fa51d2d72826f7e26625b7c.jpg";
        }
    );
    message = "success";
}

这是我的代码:

override func viewDidLoad() {
            super.viewDidLoad()
            let api = "http://jjd.imlc.me/api/index/"

            manager.GET(
                api,
                parameters: nil,
                success: onSuccess,
                failure: onFailure
            )
        }


        func onSuccess(operation: AFHTTPRequestOperation!, responseObject: AnyObject!) -> Void{
            let description = responseObject.description
            print(description)
        }

1 个答案:

答案 0 :(得分:0)

您将使用JSON文档转换为文本的JSON文档混淆,解析并转换为字典,并显示其描述。

字典的描述不是JSON文档。你看到的是正常的。没什么好担心的。