Reputation: 661
I have a question related to serialising list/array to JSON. This is done in a WFS and I'm using it's serialization (ie not doing any on my own) This is the rough code of what I have:
[DataContract]
public class MyObject
{
[DataMember]
string name;
[DataMember]
string value;
public MyObject(string n, string v)
{
name = n;
value = v;
}
}
Then I have a list of these objects:
List <MyObject> lst = new List <MyObject>();
lst.add(new MyObject("Surname", "Smith"));
return lst;
Now the resultant JSON is something like:
[{"name":"Surname", "value":"Smith"}]
What I would however like to get is:
[{"Surname":"Smith"}]
What am I doing wrong in my object definition, or elsewhere?
Thanks
Upvotes: 0
Views: 757
Reputation: 149
Use json.net from newtonsoft. It serialises in the form you want.
Upvotes: 1