0

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

1 Answer 1

1

Use json.net from newtonsoft. It serialises in the form you want.

Sign up to request clarification or add additional context in comments.

1 Comment

yes but it returns in string format which breaks things form me (ie: it inserts escape characters). I also don't really want to use that library if WCF already has serialization, would like to avoid 3rd party dependence.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.