Alamofire错误的JSON响应顺序

时间:2017-08-18 15:26:54

标签: json swift alamofire

我使用Alamofire填充TableView。 这是我的代码的摘录:

var arrRes = [[String:AnyObject]]()
        Alamofire.request(api_url5).responseJSON { (responseData) -> Void in
            if((responseData.result.value) != nil) {
                let swiftyJsonVar = JSON(responseData.result.value!)

                if let resData = swiftyJsonVar["data"].arrayObject {
                    self.arrRes = resData as! [[String:AnyObject]]
                    print (api_url5)
                    print (self.arrRes)
                }
                if self.arrRes.count > 0 {
                    self.tblDetail.reloadData()
                }
            }
        }

请求有"排序"在Postman中输出正确顺序的参数。但是表中的项目顺序错误,我收到的输出也是print (self.arrRes)

如何保留我从API获得的订单?

邮递员的命令:

{
    "data": [
        {
            "we": "text",
            "de": "text",
            "se": "text",
            "ve": "text",
            "qe": "text",
            "ne": "text"
        },
{
            "we": "wer",
            "de": "wer",
            "se": "wer",
            "ve": "wer",
            "qe": "wer",
            "ne": "wer"
        }
    ]
}

在控制台中订购:

{
    "data": [
    {
            "we": "wer",
            "de": "wer",
            "se": "wer",
            "ve": "wer",
            "qe": "wer",
            "ne": "wer"
        },
        {
            "we": "text",
            "de": "text",
            "se": "text",
            "ve": "text",
            "qe": "text",
            "ne": "text"
        }

    ]
}

1 个答案:

答案 0 :(得分:0)

您需要将postman中使用的sort参数添加到api请求中:

Alamofire.request(api_url5, parameters: ["sort":"true"]).responseJSON {