本文介绍了从json字符串创建XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试从json字符串制作xml
Trying to make a xml from a json string
var serializer = new JavaScriptSerializer();
var json1 = "[count:{first:1,second:2,third:3},{first:11,second:22,third:33}]";
var jsons = serializer.Serialize(json1);
dynamic jsona = serializer.Deserialize(json1, typeof(object));
var xmld = new XDocument(new XElement("count", jsona.Select(c =>
new XElement("first", (string)c["first"]),
new XElement("second", (string)c["second"]),
new XElement("third", (string)c["third"]))
)
);
错误消息:
Error Message:
Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type.
我尝试过:
我确保每个元素都有一个新的XElement。错误是c。此外,serializer.Serialize()返回[object,Object],[object,Object]。我希望它像Javascript JSON.stringify()。
What I have tried:
I have made sure that here is one "new XElement" for each element. The error iswith "c". Also, serializer.Serialize() is returning "[object,Object],[object,Object]". I am hoping it is like Javascript JSON.stringify().
推荐答案
这篇关于从json字符串创建XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!