【发布时间】:2014-01-25 09:55:37
【问题描述】:
我需要将一些 Json 转换为 XML,但是当我这样做时,它会删除所有空数组/列表/集合/等...
如何让它将数组包含为空项?
示例 Json:
{
"EmptyCollection": [],
"OtherPorperty\": "TestValue"
}
C#代码:
var jsonString = "{ \"EmptyCollection\": [], \"OtherPorperty\":\"TestValue\" }";
var xmlDoc = JsonConvert.DeserializeXmlNode(jsonString, "root", true);
Console.WriteLine(xmlDoc.InnerXml);
实际结果是
<root>
<OtherPorperty>TestValue</OtherPorperty>
</root>
想要的结果是
<root>
<EmptyCollection></EmptyCollection>
<OtherPorperty>TestValue</OtherPorperty>
</root>
or
<root>
<EmptyCollection />
<OtherPorperty>TestValue</OtherPorperty>
</root>
使用 writeArrayAtribute 似乎不起作用。
【问题讨论】:
标签: c# xml arrays serialization json.net