I’m new in json and got some problems trying to serialize my objects with specific data types.
I’m trying to serialize my XElement object into Newtonsoft json. Here is my code:
var nodes = new XElement("nodes");
nodes.Add(new XElement("name", "Anna"));
nodes.Add(new XElement("group", 0));
context.Response.Write(JsonConvert.SerializeXNode(nodes, Formatting.Indented, true));
the response is:
{
"nodes": [
{
"name": "Anna",
"group": "0"
}
]}
I need the Xelement GROUP converted to integer (“group”: 0) but it is always in strnig format. How can I manage data types?
Thank you
If serializing from XElement is not a must, you can use
ExpandoObject