猿问

在不使用唯一属性名的情况下反序列化JSON

我有一个类似于以下内容的json字符串


{

    "1ST": {

        "name": "One",

        "symbol": "1st"

    },

    "2ND": {

        "name": "Two",

        "symbol": "2nd"

    }

}

我正在尝试将其序列化为C#对象。看起来它正在创建字典,所以我创建了以下结构


public class Response

{

    public Dictionary<string, Item> Objects { get; set; }

}


public class Item

{

    public string name { get; set; }

    public string symbol { get; set; }

}

并在序列化过程中运行以下命令


response = JsonConvert.DeserializeObject<Response>(jsonString);

它不会在反序列化方面引发错误,但我的回答只是返回为null。我想念什么?


饮歌长啸
浏览 171回答 2
2回答
随时随地看视频慕课网APP
我要回答