2017-02-09 95 views
-2

我如何與json.net這個處理: https://raw.githubusercontent.com/VoiDGlitch/WarframeData/master/JSON/MissionDecks.jsonjson.net使用陌生的格式

這些都是類:

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 「位置」:空
2 「位置」:[字符串]
3. 「位置」: 「串」 「串」]

我如何處理呢?與自定義轉換器?

建議?

+1

請張貼[MCVE。另外,你的意思是[標籤:C#]? –

+0

問題開始於行261,在這裏你有以下幾點:'{ 「位置」: { 「海王星,指數」: 「耐力,MT_ARENA,FC_CORPUS,NT_SUB_MISSION」 } ]}'這個位置是一個對象,而不是一個字符串。你想如何反序列化它? – dbc

回答

2

讓你的基類繼承的字典:

class TennoItem : Dictionary<string, TennoData> 
{ 

} 

您應該使用數組列表:

編輯:DBC是正確的,開始行261的位置是一個對象。嘗試使用對象類型:

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); 

嘗試使得位置Dictionary對象:

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> 
{ 
} 
+0

這工作感謝:) – tuttomax