3

Is there a way to deserialize such json

{
  "photos": [
    19,
    {
      "pid": 288777129,
      "aid": -6
    },
    {
      "pid": 286441792,
      "aid": -6
    },
    {
      "pid": 114893258,
      "aid": 34465839
    }
  ]
}

with C# DataContractJsonSerializer without modifying the source. I mean the first element 19.

4
  • JSON Arrays are not restricted to one type (So the json is valid), in fact in javascript those objects would be all considered as different types in a sense because they are just generic object literals. Commented Nov 22, 2012 at 14:54
  • I've edited the question title to be more correct. Commented Nov 22, 2012 at 14:56
  • Did you find an answer? Or you ended up not using DataContract Commented Jul 3, 2014 at 21:20
  • 1
    @FYaqoob, i gave up using DataContractJsonSerializer and switched to custom converter solution with Json.NET Commented Jul 4, 2014 at 11:59

1 Answer 1

1

I usually use the JavascriptSerializer class instead:

JavaScriptSerializer js = new JavaScriptSerializer();
Object obj = js.DeserializeObject(str);
Response.Write(obj["photos"][0]); // 19
Sign up to request clarification or add additional context in comments.

1 Comment

Unfortunately i need DataContract support while deserializing.

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.