我已经使用google API在asp.net应用程序中获取两个区域之间的距离。
将结果作为休假
{
"destination_addresses" : [ "Dhantoli, Nagpur, Maharashtra, India" ],
"origin_addresses" : [ "Khamla, Nagpur, Maharashtra, India" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "4.2 km",
"value" : 4214
},
"duration" : {
"text" : "8 mins",
"value" : 467
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
我已将其收集为字符串并尝试获取距离文本(这是我需要的)
为此,我尝试了休闲代码,它不起作用
DistanceMatrix data = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<DistanceMatrix>(dataString);
dataString是API的结果
public class DistanceMatrix {
public string destination_addresses { get; set; }
public string origin_addresses { get; set; }
public Element rows { get; set; }
public string status { get; set; }
}
public class Element {
public Data distance { get; set; }
public Data duration { get; set; }
public string status { get; set; }
}
public class Data {
public string text { get; set; }
public string value { get; set; }
}
请帮助我从API结果中获取距离文字。
而不是使用json方法,请使用Google距离矩阵API的XML API。
返回xml响应的字符串将其收集起来并解析为休假。
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(dataString);
if (xmldoc.GetElementsByTagName("status")[0].ChildNodes[0].InnerText == "OK")
{
XmlNodeList distance = xmldoc.GetElementsByTagName("distance");
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句