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

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

看一下具体实现的代码吧

<!--#Include virtual="/Include/json.min.asp"--> <% Dim strxml Dim str '定义soap消息 strxml = "<?xml version='1.0' encoding='utf-8'?>" 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?'0'+n:n;} if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+ f(this.getUTCMonth()+1)+'-'+ f(this.getUTCDate())+'T'+ f(this.getUTCHours())+':'+ f(this.getUTCMinutes())+':'+ f(this.getUTCSeconds())+'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};} var cx=/[\?\?\?-\?\?\?\?\?-\?\?-\?\?-\?\?\?-\?]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\?\?-\?\?\?\?\?-\?\?-\?\?-\?\?\?-\?]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);})+'"':'"'+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)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';} gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null';} v=partial.length===0?'[]':gap?'[\n'+gap+ partial.join(',\n'+gap)+'\n'+ mind+']':'['+partial.join(',')+']';gap=mind;return v;} if(rep&&typeof rep==='object'){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==='string'){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}} v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+ mind+'}':'{'+partial.join(',')+'}';gap=mind;return v;}} if(typeof JSON.stringify!=='function'){JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' ';}}else if(typeof space==='string'){indent=space;} rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');} return str('',{'':value});};} if(typeof JSON.parse!=='function'){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}} return reviver.call(holder,key,value);} cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+ ('0000'+a.charCodeAt(0).toString(16)).slice(-4);});} if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/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> Set xmlDOC = nothingElse Response.Write h.Status &" " 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?'0'+n:n;} if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+ f(this.getUTCMonth()+1)+'-'+ f(this.getUTCDate())+'T'+ f(this.getUTCHours())+':'+ f(this.getUTCMinutes())+':'+ f(this.getUTCSeconds())+'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};} var cx=/[\?\?\?-\?\?\?\?\?-\?\?-\?\?-\?\?\?-\?]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\?\?-\?\?\?\?\?-\?\?-\?\?-\?\?\?-\?]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);})+'"':'"'+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)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';} gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null';} v=partial.length===0?'[]':gap?'[\n'+gap+ partial.join(',\n'+gap)+'\n'+ mind+']':'['+partial.join(',')+']';gap=mind;return v;} if(rep&&typeof rep==='object'){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==='string'){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}} v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+ mind+'}':'{'+partial.join(',')+'}';gap=mind;return v;}} if(typeof JSON.stringify!=='function'){JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' ';}}else if(typeof space==='string'){indent=space;} rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');} return str('',{'':value});};} if(typeof JSON.parse!=='function'){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}} return reviver.call(holder,key,value);} cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+ ('0000'+a.charCodeAt(0).toString(16)).slice(-4);});} if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/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>

时间: 2024-09-17 04:55:32

ASP调用WebService转化成JSON数据,附json.min.asp的相关文章

ASP调用WebService转化成JSON数据,附json.min.asp_应用技巧

首先定义SOAP数据,然后创建HTTP对象,然后使用POST提交,获取状态码为200,就说明调用成功,再进行下一步操作-- 看一下具体实现的代码吧 <!--#Include virtual="/Include/json.min.asp"--> <% Dim strxml Dim str '定义soap消息 strxml = "<?xml version='1.0' encoding='utf-8'?>" strxml = strxml

ASP调用WEBSERVICE文档

web ASP调用WEBSERVICE----INDEX----1. soap请求方式2. post请求方式3. SHOWALLNODE函数(关于节点各属性和数据显示)---------------------一.SOAP请求示例下面是一个 SOAP 请求示例.所显示的占位符需要由实际值替换.POST /WebService1/UserSignOn.asmx HTTP/1.1Host: 192.100.100.81Content-Type: text/xml; charset=utf-8Cont

web service-ajax带参数调用webService时的发送数据问题

问题描述 ajax带参数调用webService时的发送数据问题 如图,ajax带参数调用webService时的发送数据时为什么是 var poststr = "name=" + $("text1").value;而不是 var poststr = $("text1").value 解决方案 ajax调用webservice问题jquery中通过ajax调用webservice传递数组参数的问题 解决方案二: 前面那个是拼装的参数,因为你后台是

使用ASP调用WebService时不能以Name为数据库中的字段

web|数据|数据库 今天做了一下试验,发现当WebService返回的XML数据中使用了"Name"关键字作为健值时,ASP页面将无法读取整个XML文档,而出现以下错误: 无法显示 XML 页. 使用 XSL 样式表无法查看 XML 输入.请更正错误然后单击 刷新按钮,或以后重试. -------------------------------------------------------------------------------- 文本内容中发现无效字符.处理资源 'htt

json数据-fast json 如何设置long类型和String类型转换的?

问题描述 fast json 如何设置long类型和String类型转换的? fast json 如何设置long类型和String类型转换的?以方便spring mvc 使用@requestBody直接调用返回的处理过的JSON数据?详细配置说明..

c#winform调用webservice时返回的数据过多报错InnerException

问题描述 格式化程序尝试对消息反序列化时引发异常:尝试对参数http://tempuri.org进行反序列化时出错:QueryAdmScheduleResponse.InnerException消息是"反序列化对象属于类型drpb.ghnew.QueryAdmScheduleResponseBody时出现错误.读取XML数据时,超出最大字符串内容长度配额(8192).通过更改在创建XML读取器时所使用的XmlDictionaryReaderQuotas对象的MaxStringContentLen

js解析与序列化json数据(三)json的解析探讨_json

这一节我们主要讨论json的解析. JSON.parse()方法也可以接收另一个参数,该参数是一个函数,将早每个键值对上调用.为了区别JSON.stringify()接收的替换(过滤)函数(replacer),这个函数被称作还原函数(reviver),但实际上这两个函数的签名是相同的--它们都接收连个参数,一个键和一个值,而且都需要返回一个值. 如果还原函数返回undefined,则表示要从结果中删除相应的键:如果返回其他值,则将该值插入到结果中.如: 复制代码 代码如下: <html> &l

js解析与序列化json数据(一)json.stringify()的基本用法_json

早期的JSON解析器基本上就是使用JavaScript的eval()函数.由于JSON是JavaScript语法的自己,因此eval()函数可以解析.解释并返回JavaScript的对象和数组. ECMAScript 5对解析JSON的行为进行了规范,定义了全局对象JSON. JSON对象有两个方法:stringify()和parse().在最简单的情况下,这两个方法分别用于把JavaScript对象序列化为JSON字符串和把JSON字符串解析为原生JavaScript.例如: 新建一个HTML

问题:ASP.NET 中DataGrid.无法绑定从webservice传过来的数据。

问题描述 目标:ASP调用webservice接口,得到一个arraylist,然后显示在页面中其中arraylist中的元素是在webservice一方定义好的class,有两个属性name/age代码:通过webservice得到myArrayList后DisplayDataGrid.datasource=myArrayList;DisplayDataGrid.DataBinding();错误信息:DataGridwithid'DisplayDataGrid'couldnotautomati