Deserialize inconsistent JSON property

前端 未结 2 1293
名媛妹妹
名媛妹妹 2021-01-26 22:09

Hopefully someone can help me with the following inconsistency occurring in a large JSON file that I am attempting to deserialize using Newtonsoft.Json.

One of the proper

2条回答
  •  不思量自难忘°
    2021-01-26 22:16

    the easiest way (not necessarily the cleanest) would be to manually alter the string before deserialising -

    jsonString = jsonString.replace("\"roles\": {", "\"rolesContainer\": {");
    jsonString = jsonString.replace("\"roles\":{", "\"rolesContainer\": {");
    

    and then in your main code you would have both rolesContainer and roles as fields - and then merge them after

    public List roles { get; set; }
    public RoleContainer rolesContainer { get; set; }
    public class RoleContainer {
        Public List roles;
    }
    

    it's dirty, but it should work

提交回复
热议问题