ASP call WebService transform to JSON data, attach json.min.asp_ application Tips

Source: Internet
Author: User

The SOAP data is first defined, then the HTTP object is created, then the post submission is used, and the status code is 200 to indicate that the call succeeded and then the next step ...

Take a look at the actual code.

<!--#Include virtual= "/include/json.min.asp"--> <% Dim strxml Dim str ' defines a SOAP message 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://t empuri.org/' > ' strxml = strxml & "<reqcode>30000001</reqcode>" ' parameter 1 strxml = strxml & ' <sign&gt ;ssssss</sign> "' parameter 2 strxml = strxml &" </GetCategories> "strxml = strxml &" </soap:Body> "Strxm L = strxml & "</soap:Envelope>" Set h = CreateObject ("Microsoft.XMLHTTP") ' sends post message to specified URL H.open ' post ', ' htt P://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)" Displays the returned XML information If h.status = Then Set xmldoc = server. CreateObject ("MSXML"). DOMDocument ") xmldoc.load (h.responsexml) Jsontext = xmldoc.childnodes (1). Text ' converts to JSON, calling json.min.asp Set categories = Json.parse (jsontext) For i = 0 to categories. Length-1 Response.Write (CSTR) (Categories.get (i). CategoryName)) ' property for j = 0 to Categories.get (i). Labels.length-1 ' Set 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). 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 ' 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= '; 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 (/\\ (?: ["\\\/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%>

Attached: 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). 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 ' 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= '; 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 (/\\ (?: ["\\\/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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.