采用序列化字段顺序JSON.NET [英] Order of serialized fields using JSON.NET
问题描述
简短而亲切:
有没有使用指定的序列化的JSON对象字段的顺序 JSON.NET ?
这将足以指定单场始终出现第一位。
我跟着 JsonConvert.SerializeObject(键)
方法通过反射调用(其中key是一个IList)发现JsonSerializerInternalWriter.SerializeList被调用。它需要一个列表,并通过
的for(int i = 0; I< values.Count;我++){...
在这里值的IList中参数带来的。
简短的回答是......不,还有的方式来设置字段在JSON字符串中列出的顺序没有内置。
Short and sweet:
Is there a way to specify the order of fields in a serialized JSON object using JSON.NET?
It would be sufficient to specify that a single field always appear first.
I followed the JsonConvert.SerializeObject(key)
method call via reflection (where key was an IList) and found that JsonSerializerInternalWriter.SerializeList gets called. It takes a list and loops through via
for (int i = 0; i < values.Count; i++) { ...
where values is the IList parameter brought in.
Short answer is...No, there's no built in way to set the order the fields are listed in the JSON string.
这篇关于采用序列化字段顺序JSON.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!