2016-07-13 17 views
1

C#でnewtonsoftを使用して複雑な/不要に複雑なJSON出力を解析しようとしていますが、何らかの理由で常にnullが返されます。私は全面的に検索し、解決策を見つけることはできないようです。複数のオブジェクトと配列を持つC#Parse Json newtonsoft

私が解析しようとしているJSONファイルの例:これは私がこれまで持っているものである

{ 
    "success": 1, 
    "d": { 
    "gameData": { 
     "MJ2Y7tDg": { 
     "scores": [ 
      { 
      "max": 1.83, 
      "avg": 1.73, 
      "rest": 2, 
      "active": true, 
      "scoreid": "2c556xv464x0x4vtqc" 
      }, 
      { 
      "max": 3.47, 
      "avg": 3.24, 
      "rest": 2, 
      "active": true, 
      "scoreid": "2c556xv498x0x0" 
      }, 
      { 
      "max": 6.06, 
      "avg": 5.08, 
      "rest": 1, 
      "active": true, 
      "scoreid": "2c556xv464x0x4vtqd" 
      } 
     ], 
     "count": 62, 
     "highlight": [ 
      false, 
      true 
     ] 
     }, 
     "jZICYUQu": { 
     "scores": [ 
      { 
      "max": 2.25, 
      "avg": 2.13, 
      "rest": null, 
      "active": true, 
      "scoreid": "2c5guxv464x0x4vuiv" 
      }, 
      { 
      "max": 3.55, 
      "avg": 3.29, 
      "rest": null, 
      "active": true, 
      "scoreid": "2c5guxv498x0x0" 
      }, 
      { 
      "max": 3.9, 
      "avg": 3.33, 
      "rest": null, 
      "active": true, 
      "scoreid": "2c5guxv464x0x4vuj0" 
      } 
     ], 
     "count": 62, 
     "highlight": [ 
      false, 
      false 
     ] 
     } 
    } 
    } 
} 

、私は、JSONの論争に非常に新しいです:)と

public class RootObject 
    { 
     public int success { get; set; } 
     public List<d> d { get; set; } 
    } 

    public class d 
    { 
     public List<gameData> gameData { get; set; } 
    } 

    public class gameData 
    { 
     public IDictionary<string, Score> gameData{ get; set; } 
     public List<scores[]> GameList; 
    } 
    public class Score 
    { 
     public double max { get; set; } 
     public double avg { get; set; } 
     public int rest { get; set; } 
     public bool active { get; set; } 
     public string scoreid { get; set; } 
    } 

誰でもより多くのJSON論争の経験は、これを得る方法を知っていますか?

ありがとうございます。 P.S現在高校に通っています。C#

+0

他に何がある、彼は彼がにデシリアライズしようとしたクラスのコードを示して、あなたのコード –

+0

を表示してください必要? –

答えて

2

クラスの構造がJSONの構造に正しく似ていないため、パーサーはnullを返します。

public class RootObject 
{ 
    public int success { get; set; } 
    public Class_d d { get; set; } 
} 

public class Class_d 
{ 
    public Dictionary<string, GameData> gameData { get; set; } 
} 

public class GameData 
{ 
    public List<Score> scores { get; set; } 
    public int count { get; set; } 
    public bool[] highlight { get; set; } 
} 

public class Score 
{ 
    public decimal max { get; set; } 
    public decimal avg { get; set; } 
    public int? rest { get; set; } 
    public bool active { get; set; } 
    public string scoreid { get; set; } 
} 

と次のようにあなたはそれを使用することができます:クラスの正しい構造は以下のようになり

string json = "..."; // the JSON in your example 
RootObject root = JsonConvert.DeserializeObject<RootObject>(json); 
+0

ありがとうFelix-b。もう1つのことは、データをダンプする方法について、console.writelineを使ってどうやって行うかです。 –

関連する問題