처음, 나는이 요청에서 가능한 모든 경로의 거리/시간을 얻으려고 : 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역 직렬화 구글 방향 JSON JSON 및 관련 작업
I 얻었다 "클래스로 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; }
}
다음 사람 각각에 대해 하나 개의 클래스를 만들 수 있습니다.
나는 다음을 생각해 냈지만 효과가 없습니다.
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;
}
}
어떤 도움이 필요합니까?
추신 : 누구든지 나를 반복 할 수있는 방법을 보여줄 수 있다면 각 "다리"를 던지면 좋을 것입니다.
편집 : Newtonsoft를 사용하고 있습니다.
당신은 *가 작동하지 설명하는 것을 잊었다 : [1] : 이 후에는
는 정답을 살펴보십시오 ... 직접 변환 할 수 있습니다. 컴퓨터가 폭발 했습니까? –그러나 결과를 Root 객체로 deserialize하려고 시도해야합니다. 결과에서 어딘가에 중첩 된 json 객체를 자동 체리픽으로 검사 할 방법이 없습니다 –
@SirRufo 어떻게 그렇게됩니까? 편집 : 좋아, 나는 루트 객체로 시작 하겠어, 내가 그렇게 할 수 있다고 생각 했어. 그래서 멍청한 놈. – iamdlm