1

最近は、dailymotion ビデオ API を使用しています。ただし、返されたデータを ASP.NET C# アプリケーションに変換する方法がわかりません。

得る

https://api.dailymotion.com/videos?search=fun&page=3

結果

{ "page": 1,
  "limit": 2,
  "total": 218248,
  "has_more": true,
  "list": [
      { "id": "xrk9mi",
        "title": "Priyanka & Shahid Kapoor get MOBBED in local train",
        "channel": "fun",
        "owner": "xlw7uu"
      },
     { "id": "xrk8fy",
        "title": "What's Up With Gaga?: Hit On Head, Perfume Bottle Leaked, Thai Fans Angry",
        "channel": "music",
        "owner": "xofeoz" }
     ]
}
4

1 に答える 1

3

戻ってきたものと一致するクラスを宣言します。外側のクラス宣言から始めて、それを部分に分解しましょう。

public class DailyMotionVideo {
  public int page {get;set;}
  public int limit {get;set;}
  public int total {get;set;}
  public bool has_more {get;set;}
  public XXX[] list {get;set;}
}

だから私はそれらの配列を作ることができるように別のタイプである必要があるXXXで同じことをします:

public class DailyMotionVideoInternalList {
  public string id {get;set;}
  public string title {get;set;}
  public string channel {get;set;}
  public string owner {get;set;}
}

これには、戻ってその名前を最初の宣言に入れる必要があります。

public class DailyMotionVideo {
  public int page {get;set;}
  public int limit {get;set;}
  public int total {get;set;}
  public bool has_more {get;set;}
  public DailyMotionVideoInternalList[] list {get;set;}
}

public class DailyMotionVideoInternalList {
  public string id {get;set;}
  public string title {get;set;}
  public string channel {get;set;}
  public string owner {get;set;}
}

次に、使用している.NETバージョンに応じて、さまざまな方法で受信したオブジェクトをこのオブジェクトに変換できます。

すでに文字列として取得しているので、文字列は「結果」と呼ばれると仮定します。

DailyMotionVideo videoList = 
           new JavaScriptSerializer().Deserialize<DailyMotionVideo>(result);
于 2012-06-16T06:25:51.610 に答える