以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  关于读取API数据  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=72288)

--  作者:iceangellion
--  发布时间:2015/7/27 16:35:00
--  关于读取API数据

老师好,我是想请教读取外部API的方法。http://api.money.126.net/data/feed/500018,money.api,这是网易的股票数据 api接口,我怎么能把数据读取下来分析啊,虚心请教。


--  作者:大红袍
--  发布时间:2015/7/27 16:45:00
--  

Dim rqst As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://api.money.126.net/data/feed/500018,money.api")
Dim rsps As System.Net.HttpWebResponse = rqst.GetResponse
Dim stm As System.IO.Stream = rsps.GetResponseStream()
Dim reader As New System.IO.StreamReader(stm)
Dim json As String = reader.ReadToEnd
Dim idx As Integer = json.IndexOf("{")
Dim lidx As Integer = json.LastIndexOf("}")
json = json.SubString(idx+1, lidx-idx-1)
idx = json.IndexOf("{")
json = json.SubString(idx)
msgbox(json)
Dim ScriptControl As Object, data  As Object, JscriptCode As String
JscriptCode = "function toObject(json) {eval(""var o=""+json);return o;}"
ScriptControl = CreateObject("MSScriptControl.ScriptControl")
With ScriptControl
    .Language = "Javascript"
    .Timeout = -1
    .AddCode(JscriptCode)
    data = .Run("toObject", json)
End With

msgbox(data.sname)
msgbox(data.name)