Sub 高德货车()
Dim x As MSXML2.XMLHTTP60
Set x = New MSXML2.ServerXMLHTTP60
With x
.Open "GET", "https://restapi.amap.com/v4/direction/truck?width=2.5&strategy=10&size=2&weight=1.5&axis=2&origin=118.796877,32.060255&destination=121.473701,31.230416&height=1.6&load=0.9&nosteps=1&key=<用户的KEY>", False
'.setRequestHeader
.send
Dim sc As String
sc = x.responseText
' Debug.Print sc
End With
'下面要用刘永富老师的插件来解析JSON数据,因插件对单双引号有要求,故要把双引号转单引号--Chr(34)双引号--Chr(39)单引号
'《用此插件前要把JSON格式双引号转为单引号》
sc = Replace(x.responseText, Chr(34), Chr(39))
' Debug.Print sc
'事先 在刘永富的博客园网站上下载 他的插件,才能用此对象功能
Dim j As API.JSON
Set j = New API.JSON
j.Parse (sc) '将JSON数据转化为阶梯式
' Debug.Print j.ToString
Debug.Print j.GetSingleValue("$.data.route.paths.[0].distance")
End Sub