2016-06-16 1 views
0

まず時間が、私はこの要求からすべての可能なルートの距離/時間を取得しようとしている:https://maps.googleapis.com/maps/api/directions/json?origin=41.2091585,-8.5763016&destination=41.258913,-8.636942&mode=driving&alternatives=true&avoid=tolls&language=pt-PT&key=AIzaSyDuhdvLAny3MpraXKX-bahkXZJolm7KLbEデシリアライズGoogleの道順JSON JSONとの関連での作業

私だ「クラスとしてJSONを貼り付け」を使用して、以下のクラスと私は3つの異なる経路(通称「足」)を持っていると私は一つ一つの距離/時間を取得したい上記のクエリについて

public class Rootobject 
    { 
     public Geocoded_Waypoints[] geocoded_waypoints { get; set; } 
     public Route[] routes { get; set; } 
     public string status { get; set; } 
    } 

public class Route 
    { 
     public Bounds bounds { get; set; } 
     public string copyrights { get; set; } 
     public Leg[] legs { get; set; } 
     public Overview_Polyline overview_polyline { get; set; } 
     public string summary { get; set; } 
     public object[] warnings { get; set; } 
     public object[] waypoint_order { get; set; } 
    } 

public class Leg 
    { 
     public Distance distance { get; set; } 
     public Duration duration { get; set; } 
     public string end_address { get; set; } 
     public End_Location end_location { get; set; } 
     public string start_address { get; set; } 
     public Start_Location start_location { get; set; } 
     public Step[] steps { get; set; } 
     public object[] traffic_speed_entry { get; set; } 
     public Via_Waypoint[] via_waypoint { get; set; } 
    } 

public class Distance 
    { 
     public string text { get; set; } 
     public int value { get; set; } 
    } 

public class Duration 
{ 
    public string text { get; set; } 
    public int value { get; set; } 
} 

:以下のもののそれぞれに対して1つのクラスを作成します。
私は次のことを考え出しましたが、うまくいきません。

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(query); 
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 
using (var streamReader = new StreamReader(response.GetResponseStream())) 
{ 
    var result = streamReader.ReadToEnd(); 

    if (!string.IsNullOrEmpty(result)) 
    { 
     Distance t = JsonConvert.DeserializeObject<Distance>(result); 
     string distance1_Value = t.value; 
     string distance1_Text = t.text; 

     Duration d = JsonConvert.DeserializeObject<Duration>(result); 
     string duration1_Value = d.value; 
     string duration1_Value = d.text; 
    } 
} 

ヘルプがありますか?
PS:誰かが私にどのように反復するかを私に示すことができれば、それぞれの "脚"を投げて偉大になるでしょう。

編集:私はNewtonsoftを使用しています。

+0

は*動作しません。あなたのコンピュータは爆発しましたか? –

+1

しかし、結果をRootオブジェクトに逆シリアル化しようとする必要があります。結果のどこかにネストされたjsonオブジェクトを自動チェリーピックする方法はありません –

+0

@SirRufoどのようにそうですか?編集:私はRootobjectで始めるよ、私はそうすることができると思った。だからこそnoob。 – iamdlm

答えて

1

私は数日前に解決策を見つけた...まず

、私はあなたの同じことを行うが、それでも私のために働いていないので、私は、このツールによって生成されたクラスの自動車の奥深くを見て、一部のクラスには名前の最後に 's'がありませんでした。 ステップ、正しい名前の「ステップ」 正しい名前「脚」 ルート。正しい名前「ルート」

これを文書全体で修正する必要がありますか。 [1]:この後、あなたが直接変換することができます...

が正しい答えを見てみましょう あなたは*記述するのを忘れhttp://pastie.org/10935748#9

関連する問題