我如何处理json.net: https://raw.githubusercontent.com/VoiDGlitch/WarframeData/master/JSON/MissionDecks.json
这些是班级:
class TennoItem
{
public List<TennoData> Data { get; set; }
}
class TennoData
{
[JsonProperty("Locations")]
public string[] Locations { get; set; }
[JsonProperty("Rotation A")]
public string[] RotationA { get; set; }
[JsonProperty("Rotation B")]
public string[] RotationB { get; set; }
[JsonProperty("Rotation C")]
public List<string> RotationC { get; set; }
}
然后
SERIALIZER.Deserialize<Dictionary<string,TennoItem>>(json_reader);
但是我得到了字符串和null tennoitem
我看到地点可以是:
1.“地点”:null
2.“地点”:[字符串]
3.“地点”:[“string”:“string”]
我该怎么处理?使用自定义转换器?
建议?
答案 0 :(得分:2)
使您的基类继承自字典:
class TennoItem : Dictionary<string, TennoData>
{
}
您应该使用List而不是数组:
编辑:dbc是正确的,从第261行开始,Location是一个对象。尝试使用对象类型:
class TennoData
{
[JsonProperty("Locations")]
public List<object> Locations { get; set; }
[JsonProperty("Rotation A")]
public List<string> RotationA { get; set; }
[JsonProperty("Rotation B")]
public List<string> RotationB { get; set; }
[JsonProperty("Rotation C")]
public List<string> RotationC { get; set; }
}
然后:
SERIALIZER.Deserialize<TennoItem>(json_reader);
或 尝试将地理位置设为字典对象:
class TennoData
{
[JsonProperty("Locations")]
public List<Location> Locations { get; set; }
[JsonProperty("Rotation A")]
public List<string> RotationA { get; set; }
[JsonProperty("Rotation B")]
public List<string> RotationB { get; set; }
[JsonProperty("Rotation C")]
public List<string> RotationC { get; set; }
}
class Location : Dictionary<string, string>
{
}