简体   繁体   中英

Deserialize json with array of different types using DataContractJsonSerializer

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.

I usually use the JavascriptSerializer class instead:

JavaScriptSerializer js = new JavaScriptSerializer();
Object obj = js.DeserializeObject(str);
Response.Write(obj["photos"][0]); // 19

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM