Question

In my custom serializer, I do the following

var gridHeader = (GridHeader)value;
var jsonHeaderList = new JArray();

foreach (var columnDefinition in gridHeader.ColumnDefinitionList)
{
    var jsonHeader = new JObject();
    jsonHeader.Add(new JProperty("field", columnDefinition.Name));
    jsonHeader.Add(new JProperty("title", columnDefinition.Text));
    jsonHeaderList.Add(jsonHeader);
}

jsonHeaderList.WriteTo(writer);

And here is an example of the output :

[ { "field" : "something", "title" : "something" }, { "field" : "something", "title" : "something" } ] 

The big problem here, is that I need to have this output :

[ { field : "something", title : "something" }, { field : "something", title : "something" } ]

Notice the difference? There is no double quote around the field and title.

Tryed a couple of thing with Json.net to make sure those double quotes werent there, but no positive results so far...

Was it helpful?

Solution

What you're asking for is a javascript object, which isn't the same as JSON (although pretty close).

If you use JSON.parse() on json, you'll get the format you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top