而反序列化使用属性令JSON

而反序列化使用属性令JSON

本文介绍了而反序列化使用属性令JSON.Net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用反序列化像JsonConvert.DeserializeObject下面的字符串JSON对象:

I am trying to Deserialize the string to JSON Object using JsonConvert.DeserializeObject like below:

 var str = "{ Value: \"File\",Text: \"OWENS & MINOR  INFANT - 2228548\"}";
agreementnodes = JsonConvert.DeserializeObject<List<AgreementNode>>("[" + str + "]");

当JSON被转换成一个阵列的属性按字母顺序排列。例如:即使值为第一和文本字符串中的属性显示象下面这样:

When the json is converted to an array the properties are alphabetically ordered. Example : Even though Value is first and Text is in the string the properties are displayed like below:

即使在类的声明,我的价值是杉杉和文本为秒。但是,反序列化时,该属性是按字母顺序排序。

Even in the class declaration, I Value is Firs and Text is second. But when de-serializing, the properties are sorted alphabetically.

[JsonProperty(Order = 9)]
public string Value { get; set; }

[JsonProperty(Order = 10)]
public string Text { get; set; }

有什么办法留住产生的数组中的属性的顺序像我想要resultantarray [0] =价值和resultantarray的 =文字?

推荐答案

属性的排序是按照规范的定义。尽管是最新的ECMAScript(JavaScript)的规范要求有序格式,还支持新酷的应用,如:
https://cyberphone.github.io/openkeystore/resources/docs/jcs.html#ECMAScript_Compatibility_Mode

The ordering of properties are undefined according to the specification. In spite of that the most current ECMAScript (JavaScript) specification requires an ordered format which also enables new cool applications like:https://cyberphone.github.io/openkeystore/resources/docs/jcs.html#ECMAScript_Compatibility_Mode

这篇关于而反序列化使用属性令JSON.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 10:37