2011-12-30 2 views
1

DNLAサーバーから情報を取得する新しいWP7アプリケーションを開始しました。サーバーは、RESTプロトコル用のJSON言語をサポートしています。私はいくつかの調査を行い、json.netが非常にお勧めであることを発見しました。JSON.netの新機能、サンプルコード

私は私を与えるhttp://192.168.1.1:234/rest/status?media=json を使用してデータを取得することができます。 {"serverStatus":"STARTED","renderers":[{"uuid":"00a0965fa15c","ipAddress":"192.168.1.10","name":"KDL-52NX803","profileId":"9","status":"ACTIVE"},{"uuid":"1829220b083f","ipAddress":"192.168.1.13","name":"Windows Media Player","profileId":"1","status":"INACTIVE"},{"uuid":"5d70ac53cf8e","ipAddress":"192.168.1.14","name":"Unrecognized device","profileId":"1","status":"UNKNOWN"},{"uuid":"60465a95eec4","ipAddress":"192.168.1.22","name":"Playstation 3","profileId":"4","status":"UNKNOWN"},{"uuid":"001dd860bce4","ipAddress":"192.168.1.9","name":"Xbox 360","profileId":"3","status":"INACTIVE"}]}

非常に多くの新しいC#にイム、IVEは公式Json.NETのdocumenationを読んで、しかし、私は移動を取得するサンプルコードを見ることを好むだろう。 "renderers"データを収集するためにlistboxを作成し、サーバーの現在の "serverStatus"に対してTextBlockを作成しました。

誰でも助けることができる、非常に多くのあなたの努力手始めに

答えて

5

http://json2csharp.com/あなたのJSONに入れてPOCOを作成するための便利です申し上げます。

public class Renderer 
{ 
    public string uuid { get; set; } 
    public string ipAddress { get; set; } 
    public string name { get; set; } 
    public string profileId { get; set; } 
    public string status { get; set; } 
} 

public class RootObject 
{ 
    public string serverStatus { get; set; } 
    public Renderer[] renderers { get; set; } 
} 

Thisページには、serialize/dserializeの簡単な例があります。

RestSharpは、WP7をサポートする素晴らしいHTTP APIクライアントです。それはあなたのためのdeserialzieまた、独自のシリアライザ/デシリアライザを実装することができます。