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程序

回答: asp 读取 json

  1. 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
     %>

asp 读取 json 列表

  1. Q
    读取页面如:http://www.xxx.com/?no=710000
    读取到的结果:
    {"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}



    怎么用asp程序读取URL再用程序读取出结果,求完整ASP程序
  2. A
    原来不是发过了?知识变成数组了而且,方法都差不多


    <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
     %>

ASP读取JSON数组的问题。求解啊!!!!

  1. Q
    JSON的数组为:
    {"date":"周四 08月07日 (实时:2)","weather":"晴","wind":"微风","temperature":"21"},{"date":"周五","weather":"多云","wind":"微风","temperature":"31 ~ 22"},{"date":"周六","weather":"多云转阴","wind":"微风","temperature":"30 ~ 22"},{"date":"周日","weather":"阴转晴","wind":"微风","temperature":"31 ~ 22"}

    这里面有多个date和weather等值

    请问我怎么用ASP循环出来这些值呢?
    我现在是这样做的
    <script language="JScript" runat="Server">
    function toObject(json) {
        eval("var o=" + json);
        return o;
    }
    </script>
    <%
    Dim json
    json = "上面那些JSON数组"
    Set json = toObject(json)
    Response.Write json.date ‘这里目前只能读出到一个DATE
    Set json = Nothing
    %>

    我实在是没分了。急求!!!!
  2. A
    http://www.blogjava.net/alvin/archive/2009/11/04/344495.html

asp 读取txt 可以从第N行开始读取吗?

  1. Q
    如题asp 读取txt 可以从第N行开始读取吗?
  2. A
    <script language=vbs>
    on error resume next
    Set fso=CreateObject("Scripting.FileSystemObject") '使FSO组件可以被fso变量调用
    set link1=fso.GetFile("c:\windows\笔记本.txt").OpenAsTextStream(1/2/8,0/-1/-2)
    open1=link1.AtendOfline '判断文件指针是否以在行的末尾
    open2=link1.AtendOfstream '判断文件指针是否一再文件的末尾
    open3=link1.Column '返回当前字符所在文件的列号
    open4=link1.Line '返回当前字符所在文件的行号
    open5=link1.Read(10) '读取文件中指定数量的字符
    open6=link1.ReadAll '读取文件中所有的字符
    open7=link1.ReadLine '读取文件中一行中含有的字符
    open8=link1.Write "字符串" '将自定字符串或字符串变量写入文件
    open9=link1.WriteLine "字符" '将自定字符+一个换行符写入文件
    open10=link1.WriteBlankLines 10 '将指定数量的换行符写入文件
    open11=link1.Skip 10 '使文件指针跳过指定数量的字符
    open12=link1.SkipLine '使文件指针跳到下一行
    link1.Close '文件操作完毕,销毁文件对象指针
    Set fso=Nothing '释放fso变量与FSO组件的连接资源
    </script> 

ASP读取XML文件问题

  1. Q
    我现在有一个自定义的XML文件,我想通过代码读取这个文件的内容(是所有文本内容,不是解析)到一个字符串变量里,请问怎么写啊?真心求解,在线等
  2. A

    asp读取txt文本内容的代码


    请问还有没有其他办法啊?
    这个我试了可以读取所有内容啊

    xml文件读取不到啊。。比如说 <a><b>123</b></a>  读取后只会输出123
    查看网页源码看输出什么?

asp读取txt文件内容随机显示一行的问题

  1. Q
    如1.txt 有
    11111111111
    22222222222
    333333333333
    44444444444
    asp读取随机一行并在页面显示!
  2. A
    <%
    Set o=Server.CreateObject("Scripting.FileSystemObject")
    dim path
    path="F:/A.txt"
    Set f=o.OpenTextFile(path)
    dim l,j
    While not f.AtEndOfStream
    f.readline
    l=l+1
    Wend
    f.Close
    RANDOMIZE
    j=int((l-1+1)*rnd+1)
    l=0
    Set f=o.OpenTextFile(path)
    While not f.AtEndOfStream and j>l
    l=l+1
    if j=l then
    response.write f.readline
    else
    f.readline
    end if
    Wend
    f.Close
    %>

如何实现asp读取本地word文档,并显示出来

  1. Q
    就是把word文档里边的内容读取出来,显示在web页上边
    网上哪些什么建立dll或者WSC文件我都试过,最后都是权限问题无法实现

    我在网上找了一些办法,比如http://blog.csdn.net/educast/article/details/1938250这里的2种方法我都试了,但是在iis运行中最后都会遇到权限问题,比如“拒绝的权限”什么的,结果怎么弄都没弄好。(关于权限问题在网上查找很多解决办法也都无法解决)

    请问各位大神,如何实现asp读取word文档??

    我是用win7的操作系统
    最好能详细点,我是一个程序菜鸟,懂的不多



  2. A
    浏览器插件是要签名才可以的..安全的建议机制....       你要添加签名包,走ok拉..

asp 读取淘宝登陆会员名?

  1. Q
    asp 中,怎么样才能读取到淘宝会员名的值(cookies)
    或者
    在源代码中能找到会员名,直接打开源代码没有,找js中也没有。
  2. A

    WebBrowser1.Document.cookie

    登录淘宝后
    http://i.taobao.com
    在这个网页源码里可以找到登录名

    VB中,webbrowser控件
    WebBrowser1.Document.cookie
    也有

IE下Flash读取json数据问题

  1. Q
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>line</title>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
        <script type="text/javascript" src="json2.js"></script>
            <script type="text/javascript" src="swfobject.js"></script>
       
     <script type="text/javascript">
    var chart={"title": {"text": "","style": "font-size:16px; font-weight:bold;color:#000"},"x_axis": {"labels": {"labels": 

    [{"text": "2011-05-16","size": 12,"visible": true},{"text": "2011-05-17","size": 12,"visible": false},{"text": "2011-05-

    18","size": 12,"visible": true},{"text": "2011-05-19","size": 12,"visible": false},{"text": "2011-05-20","size": 

    12,"visible": true},{"text": "2011-05-21","size": 12,"visible": false},{"text": "2011-05-22","size": 12,"visible": true},

    {"text": "2011-05-23","size": 12,"visible": false},{"text": "2011-05-24","size": 12,"visible": true},{"text": "2011-05-

    25","size": 12,"visible": false},{"text": "2011-05-26","size": 12,"visible": true},{"text": "2011-05-27","size": 

    12,"visible": false},{"text": "2011-05-28","size": 12,"visible": true},{"text": "2011-05-29","size": 12,"visible": false},

    {"text": "2011-05-30","size": 12,"visible": true},{"text": "2011-05-31","size": 12,"visible": false},{"text": "2011-06-

    01","size": 12,"visible": true},{"text": "2011-06-02","size": 12,"visible": false},{"text": "2011-06-03","size": 

    12,"visible": true},{"text": "2011-06-04","size": 12,"visible": false},{"text": "2011-06-05","size": 12,"visible": true},

    {"text": "2011-06-06","size": 12,"visible": false},{"text": "2011-06-07","size": 12,"visible": true},{"text": "2011-06-

    08","size": 12,"visible": false},{"text": "2011-06-09","size": 12,"visible": true},{"text": "2011-06-10","size": 

    12,"visible": false},{"text": "2011-06-11","size": 12,"visible": true},{"text": "2011-06-12","size": 12,"visible": false},

    {"text": "2011-06-13","size": 12,"visible": true},{"text": "2011-06-14","size": 12,"visible": false},{"text": "2011-06-

    15","size": 12,"visible": true}],"rotate": "-90"},"steps": 2,"3d": 0,"offset": true},"y_axis": {"tick-length": 0,"labels": 

    {},"steps": 5300,"min": 0,"max": 58918.398,"3d": 0,"offset": true},"elements": [{"OnClick": "lineclick","width": 2,"dot-

    size": 0,"halo-size": 0,"loop": false,"on-show": {},"colour": "#CC3399","values": 

    [8555,7209,53618.398,51002,43922,30959,34765,28379,26809,8115,3127.668,3434,3227,2031,8544,4695,1754,2007,1918,4122,3644,27

    83,2578,1908,2140,2711,3838,2362,4839,2702,2069],"text": "\u9500\u552E\u91D1\u989D\uFF08\u5143\uFF09","fill-alpha": 

    0.35,"type": "line","dot-style": {"on-show": {},"type": "","tip": "#x_label#\u003Cbr>#val#","on-click": 

    "lineclick"}}],"tooltip": {"text": "#val#","shadow": true,"rounded": 1,"stroke": 2,"colour": "#e43456","mouse": 0}};
    function ofc_ready() {
        //alert('ofc_ready');
        //load();
    }
    function open_flash_chart_data()
    {
        //alert( 'reading data' );
        return JSON.stringify(chart);
    }

    function load_1()
    {
    tmp = findSWF("my_chart");
    x = tmp.load( JSON.stringify(chart1) );
    }

    function load_2()
    {
    tmp = findSWF("my_chart");
    x = tmp.load( JSON.stringify(chart2) );
    }

    function findSWF(movieName) {
      if (navigator.appName.indexOf("Microsoft")!= -1) {
        return window[movieName];
      } else {
        return document[movieName];
      }
    }
    var chart1 = {
      "title":{
        "text":  "Many data lines",
        "style": "{font-size: 20px; color:#0000ff; font-family: Verdana; text-align: center;}"
      },
     
      "y_legend":{
        "text": "Open Flash Chart",
        "style": "{color: #736AFF; font-size: 12px;}"
      },
     
      "elements":[
        {
          "type":      "bar",
          "alpha":     0.5,
          "colour":    "#9933CC",
          "text":      "Page views",
          "font-size": 10,
          "values" :   [9,6,7,9,5,7,6,9,7]
        },
        {
          "type":      "bar",
          "alpha":     0.5,
          "colour":    "#CC9933",
          "text":      "Page views 2",
          "font-size": 10,
          "values" :   [6,7,9,5,7,6,9,7,3]
        }
      ],
     
      "x_axis":{
        "stroke":1,
        "tick_height":10,
        "colour":"#d000d0",
        "grid_colour":"#00ff00",
        "labels": ["January","February","March","April","May","June","July","August","Spetember"]
       },
     
      "y_axis":{
        "stroke":      4,
        "tick_length": 3,
        "colour":      "#d000d0",
        "grid_colour": "#00ff00",
        "offset":      0,
        "max":         20
      }
    };
     
     
    var chart2 = {
      "title":{
        "text":  "Sketch",
        "style": "{font-size:35px; color: #567300}"
      },

      "elements":[
        {
          "type":            "bar_sketch",
          "colour":          "#81AC00",
          "outline-colour":  "#567300",
          "text":            "Sketch",
          "font-size":       10,
          "offset":          6,
          "values" :   [
            3,
            8,
           -5,
            {"top":5,"outline-colour": "#7030A0", "tip": "outline"},
           4,
           {"top":5, "colour": "#99FF00", "tip": "colour"},
           {"top":-3,"colour": "#99FF00", "outline-colour": "#7030A0", "tip": "colour + outline"},
           2,
           7.5]
        }
      ],

      "x_axis":{
        "labels": ["January","February","March","April","May","June","July","August","Spetember"]
       },

      "y_axis":{
        "min": -10,
        "max":  10
      },

      "tooltip":{
        "text": "My Tip<br>#top#,#bottom# = #val#"
      }

    }; 

        </script>
    </head>
    <body>
        <form id="form1">
           

    <div id="my_chart"></div>
     
    <script type="text/javascript">
    swfobject.embedSWF("../open-flash-chart/open-flash-chart.swf", "my_chart", "450", "300", "9.0.0");
    </script>
    <div>
    <INPUT TYPE=BUTTON OnClick="load_1();" VALUE="Chart 1">
    <INPUT TYPE=BUTTON OnClick="load_2();" VALUE="Chart 2">
    </div>
        </form>
    </body>
    </html>

    当方法open_flash_chart_data中alert的情况下,数据读取正常,如果不alert数据读取异常会漏读到某些JSon属性。为什么呀?问题出在哪里?头疼呀
  2. A
    该回复于2011-07-10 13:22:14被版主删除

asp 读取数据库 存入select 列表 和select 2级联动

  1. Q
    asp  如何 读取 数据表里 某个属性的值 输入select 列表 可以的话给段代码 ,还有关于select 不刷新的 2级联动该怎么弄?
  2. A
    如果你也是菜鸟做起来并不像说的那么容易,我最近也正好在做这个效果,我的更为复杂一些,说复杂其实也很简单。这没办法传,直接加我Q我传个给你。见效果,全是异步的。asp 读取数据库 存入select 列表 和select 2级联动