Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Trying to make a xml from a json string

C#
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.


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().
Posted
Updated 27-Mar-17 7:57am
v2
Comments
F-ES Sitecore 27-Mar-17 10:36am    
How do you want the resulting xml to look?

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900