日期:2014-05-16  浏览次数:20917 次

asp 读取 json
读取页面如:http://www.xxx.com/?id=13116711097
读取到的结果:
{"resultcode":"200","reason":"Return Successd","result":{"province":"浙江","city":"杭州","areacode":"0571","zip":"310000","company":"中国联通","card":"联通130卡"},"error_code":0}


怎么用asp程序读取URL再用程序读取出结果,求完整ASP程序
------解决方案--------------------
Microsoft.XMLHTTP获取到字符内容后用jscript eval生成下json对象,然后返回给asp
<script runat="server" language="jscript">
    function getJSON(v) {return eval('('+v+')');}
</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/?id=13116711097")
s="{""resultcode"":""200"",""reason"":""Return Successd"",""result"":{""province"":""浙江"",""city"":""杭州"",""areacode"":""0571"",""zip"":""310000"",""company"":""中国联通"",""card"":""联通130卡""},""error_code"":0}"
set o=getJSON(s)
response.Write(o.result.province)

set o=nothing
 %>