本帖最后由 ghostjiao 于 2014-11-5 08:47 编辑
- Sub json()
- Dim objXML, objJS, objS, tt$, p, arr(1 To 100, 1 To 9), n%, j%, ar
- Set objJS = CreateObject("MSScriptControl.ScriptControl")
- Set objXML = CreateObject("MSXML2.XMLHTTP")
- ar = Array("aqi", "area", "pm2_5", "pm2_5_24h", "position_name", "primary_pollutant", "quality", "station_code", "time_point")
- With objXML
- .Open "GET", "http://www.pm25.in/api/querys/pm2_5.json?city=%E7%8F%A0%E6%B5%B7&token=5j1znBVAsnSf5xQyNQyq", False
- .send
- tt = "var mydata=" & .responsetext
- End With
- With objJS
- .Language = "javascript"
- .addcode tt
- Set objS = .codeobject
- For Each p In CallByName(objS, "mydata", VbGet)
- n = n + 1
- For j = 1 To 9
- arr(n, j) = CallByName(p, ar(j - 1), VbGet)
- Next
- Next
- End With
- Range("a1").Resize(1, 9) = ar
- Range("a2").Resize(n, 9) = arr
- End Sub
复制代码
|