How to deserialize JSON with duplicate property names in the same object

后端 未结 3 1158
长发绾君心
长发绾君心 2020-11-29 12:24

I have a JSON string that I expect to contain duplicate keys that I am unable to make JSON.NET happy with.

I was wondering if anybody knows the best way (maybe usin

3条回答
  •  既然无缘
    2020-11-29 12:49

    You should not be using a generic type of object, it should be a more specific type.

    However you json is malformed which is you rmain problem

    You have :

    "{ \"HiThere\":1, \"HiThere\":2, \"HiThere\":3 }"
    

    But it should be:

    "{"HiTheres": [{\"HiThere\":1}, {\"HiThere\":2}, {\"HiThere\":3} ]}"
    

    Or

    "{ \"HiThereOne\":1, \"HiThereTwo\":2, \"HiThereThree\":3 }"
    

    You json is one object with 3 fields with all the same name ("HiThere"). Which wont work.

    The json I have shown gives: An array (HiTheres) of three objects each with a field of HiThere Or One object with three field with different names. (HiThereOne, HiThereTwo, "HiThereThree)

    Have a look at http://jsoneditoronline.org/index.html And http://json.org/

提交回复
热议问题