网络编程 
首页 > 网络编程 > 浏览文章

ASP调用WebService转化成JSON数据,附json.min.asp

(编辑:jimmy 日期: 2024/5/9 浏览:3 次 )

首先定义SOAP数据,然后创建HTTP对象,然后使用POST提交,获取状态码为200,就说明调用成功,再进行下一步操作……

看一下具体实现的代码吧

<!--#Include virtual="/Include/json.min.asp"-->
<%
Dim strxml
Dim str

'定义soap消息
strxml = "<"
strxml = strxml & "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"       
strxml = strxml & "<soap:Body> "
strxml = strxml & "<GetCategories xmlns='http://tempuri.org/'>"
strxml = strxml & "<reqcode>30000001</reqcode>" '参数1
strxml = strxml & "<sign>ssssss</sign>" '参数2
strxml = strxml & "</GetCategories>"
strxml = strxml & "</soap:Body>"
strxml = strxml & "</soap:Envelope>"

Set h = createobject( "Microsoft.XMLHTTP")
'向指定的URL发送Post消息
h.open "POST", "http://www.domain.com/WebService.asmx", False
h.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
h.setRequestHeader "Content-Length",LEN(strxml)
h.setRequestHeader "SOAPAction", "http://tempuri.org/GetCategories"
h.send (strxml)

'显示返回的XML信息

If h.Status = 200 Then
  Set xmlDOC = server.CreateObject("MSXML.DOMDocument")
  xmlDOC.load(h.responseXML)
  jsonText = xmlDOC.childNodes(1).Text 
  
  '转换成JSON,调用json.min.asp
  Set categories = JSON.parse(jsonText)
  
  for i = 0 to categories.Length -1
    Response.Write(CStr(categories.get(i).CategoryName)) '属性
    for j = 0 to categories.get(i).Labels.Length - 1 '集合
      Response.Write(CStr(categories.get(i).Labels.get(j).LabelName))
    next
  next
  <pre name="code" class="vb"><script language="javascript" runat="Server">
if(!Array.prototype.get){Array.prototype.get=function(prop){return this[prop];}}"use strict";if(!this.JSON){JSON={};}
(function(){function f(n){return n<10"\x00-\x1f\x7f-\x9f\"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'"':'"'+string+'"';}
function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key);}
if(typeof rep==='function'){value=rep.call(holder,key,value);}
switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)"\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-" " Response.Write h.StatusTextEnd if%>

附:json.min.asp
<script language="javascript" runat="Server">
if(!Array.prototype.get){Array.prototype.get=function(prop){return this[prop];}}"use strict";if(!this.JSON){JSON={};}
(function(){function f(n){return n<10"\x00-\x1f\x7f-\x9f\"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'"':'"'+string+'"';}
function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key);}
if(typeof rep==='function'){value=rep.call(holder,key,value);}
switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)"\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j;}
throw new SyntaxError('JSON.parse');};}}());
</script>
上一篇:什么是ASP?如何打开ASP文件
下一篇:ASP中解决“对象关闭时,不允许操作。”的诡异问题……
一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网