网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 asp 读取 json 列表解决思路
内容
    怎么用asp程序读取url再用程序读取出结果,求完整asp程序
    ------解决方案--------------------
    原来不是发过了?知识变成数组了而且,方法都差不多
    <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()
    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
    %>
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/14 17:13:18