我正在尝试理解如何正确反序列化这个对象。
{
"_note": "You are currently authenticated with the API using your OPSkins login session cookies.",
"status": 1,
"time": 1500460072,
"response": {
"AK-47 | Aquamarine Revenge (Battle-Scarred)": {
"op_7_day": 999,
"op_30_day": 932
},
"AK-47 | Aquamarine Revenge (Factory New)": {
"op_7_day": 2738,
"op_30_day": 2665
}
}
}
这是我的类结构
public class OpRoot
{
public string _note { get; set; }
public int status { get; set; }
public int time { get; set; }
public OpResponse response { get; set; }
}
public class OpResponse
{
public Dictionary<string, OpItem> items { get; set; }
}
public class OpItem
{
public int op_7_day { get; set; }
public int op_30_day { get; set; }
}
这是我尝试反序列化的方式:
OpRoot OpInstance = JsonConvert.DeserializeObject<OpRoot>(readerResponse);
我尝试将字典转换为列表,但在尝试调用“items”对象时仍然出现了“System.NullReferenceException”的相同结果。
Console.WriteLine(OpInstance.response.items.Values);
所以我认为问题在于“OpResponse”类的代码。大部分代码之前都可以使用,但是使用另一种JSON结构时出现了问题。
希望能得到任何帮助。
编辑:修正了拼写错误。
{
开头。 - Christoph K