反序列化数组的数组



My RootObject

       [JsonProperty("status")]
        public string Status {
            get;
            set;
        }
        [JsonProperty("error")]
        public ErrosHelper Error {
            get;
            set;
        }
        [JsonProperty("resource")]
        public List<List<int>> Resource {
            get;
            set;
        }

Json响应。

{"地位":"成功"、"资源":{" 1 ":{"1":"30","2":"23","3":"43"},"2":{"1":"34","2":"54","3":"32"},"3":{"1":"56","2":"43","3":"39"}," 4 ":{"1":"23","2":"32","3":"31"},"5":{"1":"34","2":"37","3":"29"},"6":{"1":"38","2":"34","3":"45"},"7":{"1":"67","2":"53","3":" 67 "},"8":{"1":"45"、"2":"23","3":" 78 "},"9":{"1":"54","2":"44","3":"56"},"10":{"1":"46","2":"23","3":"45"},"11":{"1":"77","2":"56","3":" 78 "},"12":{"1":"34","2":"21","3":" 65 "},"13":{"1":"46","2":"23","3":"45"},"14":{"1":"77","2":"56","3":"78"}, " 15 ":{"1":"34","2":"21","3":" 65 "},"16":{"1":"46","2":"23","3":"45"},"17":{"1":"77","2":"56","3":" 78 "},"18":{"1":"34","2":"21","3":" 65 "},"19":{"1":"46","2":"23","3":"45"},"20":{"1":"77","2":"56","3":" 78 "}}}

我有响应,它给我Json字符串。我如何将这个字符串反序列化为我的对象?

您的对象错误。您所展示的JSON并不是一个int类型列表的列表,而是一个字典的字典。

如果你把它改成

public class Root {
    [JsonProperty("status")]
    public string Status {
        get;
        set;
    }
    [JsonProperty("resource")]
    public Dictionary<string, Dictionary<string, int>> Resource {
        get;
        set;
    }
}

使用JsonConvert.DeserializeObject<Root>(json);

将正确反序列化

相关内容

  • 没有找到相关文章