0

我试图发送以下 JSON Body

{
    "ID": "3d7effda-8e3a-4254-bc4a-32c473ce473f",
    "Projects": [
        {
            "__type": "ProductEvaluationReference:#abc.Think.Projects",
            "ID": "01ff01cb-d3a5-4a36-b274-446cdcbd93a2",
            "Type": "ProductEvaluation"
        },
        {
            "__type": "FinancialAssessmentReference:#abc.Think.Projects",
            "ID": "403030bf-dc7d-4e4f-ae5b-b25c6b61e986",
            "Type": "FinancialAssessment"
        },
        {
            "__type": "ProductSurveyReference:#abc.Think.Projects",
            "ID": "8e43e41f-d200-4508-9c48-f0ee6e8baf99",
            "Type": "ProductSurvey"
        },
        {
            "__type": "ProductSurveyReference:#abc.Think.Projects",
            "ID": "e066c8ae-e268-4e9d-b2b0-ecb888d9a238",
            "Type": "ProductSurvey"
        }
    ]
}
}

这完美地工作。但是,如果我更改请求中字段的顺序,__type即代替字典中的第一个键并将其设置为第二个键。我得到一个错误Cannot create abstract class。例如:

{
    "ID": "403030bf-dc7d-4e4f-ae5b-  b25c6b61e986",
    "_type": "FinancialAssessmentReference:#abc.Think.Projects",
    "Type": "FinancialAssessment"
}

我在MSDN上阅读了以下内容

JSON 对象中的类型提示位置
请注意,类型提示必须首先出现在 JSON 表示中。这是键/值对的顺序在 JSON 处理中很重要的唯一情况。

这真的是我们需要的吗,ORDERED JSON还是我在服务器端出了点问题。谢谢

4

1 回答 1

1

是的,我们确实需要一个有序的 JSON。我创建了一个 NSDictionary 的子类,为键添加一些排序。

于 2013-12-22T18:42:17.593 回答