2011-09-12 1 views
-1

可能な重複したデータを取得する方法:
How do i parse json?は、JSONから

は私のasp.net C#でJSONデータをデシリアライズする方法を教えてください。ここで

{ 
    "errstr": "All downloded vedios ", 
    "errcode": 0, 
    "result": { 
     "videos": [ 
      { 
       "id": "22", 
       "name": "Ashley", 
       "price": "0.49", 
       "size": "3712310" 
      } 
     ], 
     "trailer": [ 
      { 
       "id": "1", 
       "trailer_name": "charl1", 
       "status": "1" 
      }, 
      { 
       "id": "2", 
       "trailer_name": "charl2", 
       "status": "1" 
      } 
     ] 
    } 
} 

私は2本のオブジェクトのビデオやトレーラーを持っている: は、実は私のような二つのオブジェクトとJSONデータを持っています。私のコードでこれらのデータを取得するプロセスを教えてください。

答えて

0

JSON .NET - あなたは例のJSONファイル

{ 
"GeminiURL":"https://gemini.com/Gemini" 
,"Language":"en" 
,"Log":{"Debug":true,"Info":true,"Warn":true,"FileName":"d:\\temp\\tfsgemini.log"} 
} 

ためのネストされたメンバー を持つクラスを作成する必要がありhttp://json.codeplex.com/

1

public class Settings 
{ 
    public string GeminiURL; 
    private LogSettings _log; 
    public LogSettings Log 
    { 
     get { return _log = _log ?? new LogSettings(); } 
     set { _log = value; } 
    } 
    public string Language; 

    public Settings() 
    { 
     // defaule settings can be assigned here; 
    } 
} 
public class LogSettings 
{ 
    public bool Debug; 
    public bool Info = true; 
    public bool Warn = true; 
    public string FileName; 
} 

とC#クラスでserializaedと直列化復元されますデシリアライゼーションコードは次のようになります。

public static T Load(string fileName) 
{ 
    T t = new T(); 
     if (File.Exists(fileName)) 
      t = (new JavaScriptSerializer()).Deserialize<T>(File.ReadAllText(fileName)); 
     else 
      Save(t); 
    return t; 
}