Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 正在交换字典值_Ios_Json_Swift_Nsdictionary - Fatal编程技术网

Ios 正在交换字典值

Ios 正在交换字典值,ios,json,swift,nsdictionary,Ios,Json,Swift,Nsdictionary,我需要将输入json作为- [{"QuestionId":77,"OptionId":297}] 然而,当我执行array.append(dict)时,我得到的数组是与包含键值的字典顺序相反的数组 [["OptionId": 297, "QuestionId": 77]] “OptionId”和“QuestionId”似乎在交换位置。请,谁能纠正我从这个问题 调用webservice时,我还需要传递一个json作为输入参数。我用阿拉莫菲尔做的。我的json输入是-[{“QuestionId”

我需要将输入json作为-

[{"QuestionId":77,"OptionId":297}]
然而,当我执行array.append(dict)时,我得到的数组是与包含键值的字典顺序相反的数组

[["OptionId": 297, "QuestionId": 77]]
“OptionId”和“QuestionId”似乎在交换位置。请,谁能纠正我从这个问题

调用webservice时,我还需要传递一个json作为输入参数。我用阿拉莫菲尔做的。我的json输入是-[{“QuestionId”:77,“OptionId”:297},{“QuestionId”:78,“OptionId”:304}] 我该怎么做? 我试过了 func callPostAnswersAPI(参数:数组>){

在print(str!)时,我得到了正确的json格式,但是在将其传递给alamofire.request后,它添加了反斜杠。因此,响应进入.failure循环。
我是否遵循了正确的过程?

JSON规范中将JSON对象定义为无序集合

对象是一组无序的名称/值对。 ()

如果订单对您很重要,那么您应该使用不同的收集类型。

来自:

每个字典都是键-值对的无序集合


它没有顺序,因此没有进行交换。

字典值没有顺序,没有交换,因为没有顺序。谢谢你的回答。我需要做什么才能恢复相同的顺序?使用不同的数据结构。@Dyana如果要保持顺序,请使用任何有顺序的集合,例如Arrays.my jsoninput paramater是一个字典数组。你能简单介绍一下例子吗?我不知道该如何处理它。我是swift新手。
    var request = URLRequest(url: URL(string: "http://192.168.1.56/OnlineExamPortal/api/Question/PostAnswer")!)        
    request.httpBody = try! JSONSerialization.data(withJSONObject: parameters, options: .prettyPrinted)
    let str = String(data: request.httpBody!, encoding: String.Encoding.utf8)      
    Alamofire.request(str!)
        .responseJSON { response in
            switch response.result {
            case .failure(let error):
                print(error)

                if let data = response.data, let responseString = String(data: data, encoding: .utf8) {
                    print(responseString)
                }
            case .success(let responseObject):
                print(responseObject)
            }
    }

}