怎麼用asp程式讀取URL再用程式讀取出結果,求完整ASP程式
------解決方案--------------------
原來不是發過了?知識變成數組了而且,方法都差不多http://bbs.csdn.net/topics/390776429
<script runat="server" language="jscript">
function getJSON(v) { return eval('(' + v + ')'); }
function toArray(a) {//JSON對象數組格式的字串
var dic = Server.CreateObject("Scripting.Dictionary");
for (var i = 0; i < a.length; i++) {
var obj = Server.CreateObject("Scripting.Dictionary");
for (x in a[i]) obj.Add(x, a[i][x]);
dic.Add(i, obj);
}
return dic;
}
</script>
<%
'==================================================
'從2進位資料流產生內容
'==================================================
Function BytesToBstr(strBody,CodeBase)
dim obj
set obj=Server.CreateObject("Adodb.Stream")
obj.Type=1
obj.Mode=3
obj.Open
obj.Write strBody
obj.Position=0
obj.Type=2
obj.Charset=CodeBase
BytesToBstr=obj.ReadText
obj.Close
set obj=nothing
End Function
function downpage(url)
set xhr=server.CreateObject("microsoft.xmlhttp")
xhr.open "get",url,false
xhr.send
downpage=BytesToBstr(xhr.responsebody,"gb2312")'注意你那個頁面的編碼,要不可能出亂碼
end function
's改為用Microsoft.XMLHTTP動態擷取
's=downpage("http://www.xxx.com/?no=710000")
s="{""resultcode"":""200"",""reason"":""Return Successd"",""result"":[{""id"":""1"",""province"":""陝西省"",""city"":""西安市"",""area"":""灞橋區"",""address"":""狄寨鎮南寨村""},{""id"":""2"",""province"":""陝西省"",""city"":""西安市"",""area"":""灞橋區"",""address"":""狄寨鎮潘村""}
,{""id"":""3"",""province"":""陝西省"",""city"":""西安市"",""area"":""灞橋區"",""address"":""狄寨鎮伍坊村""}],""error_code"":0}"
set o=getJSON(s)
if o.resultcode="200" then
set result=toArray(o.result)
for i=0 to result.count-1
response.Write result(i)("province")&"-"&result(i)("address")&"<br/>"
next
set result=nothing
end if
set o=nothing
%>