I'd prefer to use Microsofts System.Runtime.Serialization.Json.DataContractJsonSerializer to serialize my objects in JSON so I do not have to reference any third party assemblies.
I'm trying to serialize arrays into a JSON string. There maybe just 1 array, with every other entry being the name and other being the value.
e.g.[ "name1", "value1", "name2", "value2" ]
I wish to serialize so that the name and value appears a pair in the JSON string
e.g.
the array in .NET is [ "name1", "value1", "name2", "value2" ]
becomes
{
"name1": "value1",
"name2": "value2"
}
I have successfully achieved this with the JSON.NET JsonTextWriter by looping through the 2 arrays and adding to then using the
jsonWriter.WritePropertyName(namesAndValues[i].ToString());
jsonWriter.WriteValue(namesAndValues[i+1]);
I'm trying to do the same thing with Microsofts DataContractJsonSerializer but it doesn't seem to have the same flexibility. Is there some way?
I know I can use the JSON.NET source code itself but I'd rather use a Microsoft class if possible.