لقد كنت على اتصال مع WebService لفترة طويلة ، ولكن لا يوجد العديد من البرامج التعليمية لاستخدام ASP ، وليس من الشائع التحويل إلى JSON.
حدد أولاً بيانات SOAP ، ثم قم بإنشاء كائن HTTP ، ثم أرسله باستخدام POST ، والحصول على رمز الحالة 200 ، مما يعني أن المكالمة ناجحة ، ثم انتقل إلى العملية التالية ...
ألق نظرة على رمز التنفيذ المحدد
<!-#include virtual =/include/json.min.asp-> <٪ dim strxmldim str'finition soap message strxml = <؟ & <soap: Envelope xmlns: xsi = 'http: //www.w3.org/2001/xmlschema-instance' xmlns: xsd = 'http: //www.w3 http://schemas.xmlsoap.org/soap/envelope/ '> strxml = strxml & <saap: body> strxml = strxml & <getCategories xmlns = 'http: //tempuri.org/' 'المعلمة 2strxml = strxml & </netcategories> strxml = strxml & </soap: body> strxml = strxml & </soap: Envelope> set h = createObject (microsoft.xmlhtp)' إرسال رسالة بعد H.Open إلى url المحددة إلى orl المحددة بريد، http://www.domain.com/webservice.asmx ، falseh.setRequestHeader-type ، text/xml ؛ .org/getCategoriessh.send (strxml) 'أظهر معلومات XML التي تم إرجاعها إذا كان H.Status = 200 ثم تعيين xmldoc = server.createBject (msxml.domdocument) xmldoc.load (h.responsexml) jsontext = xmldoc.childnodes (1) .text 'تحويل إلى json ، call json.min.asp set catevories = json.parse (jsontext) for i = 0 to catevories.length -1 response.write (cstr (cstratory.get ( i) .CategoryName)) 'خاصية لـ j = 0 إلى الفئات. التالي التالي <name = code class = vb> <script اللغة = javaScript runat = server> if (! array.prototype.get) {array.prototype.get = function (prop) {return this [prop] ؛}} استخدم صارمًا ؛ if (! this.json) {json = {{ ؛ وظيفة (مفتاح) {return isFinite (this.valueof ())؟ this.getUclyear ()+'-'+f (this.getutcmonth ()+1)+'-'+f (this.getutcdate ())+'t'+f (هذا .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 ، expable =///// x00-/x1f/x7f-/x9f/؟-؟-/؟/؟/؟/؟/؟-/؟-/؟-/؟-/؟/؟ -/؟/؟-/؟/؟-/؟/؟-/؟]/g ، الفجوة ، المسافة البادئة ، meta = {'/b': '// b' ، '/t': '// t' ، '/n': '// n' ، '/f': '// f': '// f' ، '/r': '// r' ، '': '//' /':' /// '} ، rep ؛ function quote (string) {expable.lastindex = 0 ؛ return expable.test (string)؟ ''+string.replace (قابلة للهرب ، وظيفة (a) {var c = meta [a] ؛ إرجاع نوع c === 'string'؟ c: '// u'+('0000 "+A.CharCodeAt (0) .ToString (16)). شريحة (-4) ؛})+'': ''+string+'' ؛ الطول ، العقل = الفجوة ، جزئي ، القيمة = حامل [مفتاح] ؛ if (value && typeof value === 'Object' && typeof value.tojson === 'function') {value = value.tojson (key) ؛} if (typeof rep === 'function') {value = rep.call (حامل ، مفتاح ، قيمة) ؛} التبديل (typeof القيمة) {case'String ': return quote (value) ؛ case'number': return isfinite (value)؟ String (value) ؛ case'object ': if (! value) {return'null' ؛} gap+= perent ؛ partial = [] ؛ if (object.prototy.toString.apply (value) === '[object صفيف] ') {length = value.length ؛ for (i = 0 ؛ i <length ؛ i+= 1) {partial [i] = str (i ، value) ||' null '؛} v = partial.length = == 0؟ '،')+']' ؛ 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 '+ فجوة)+'/n'+mind+'}': '{'+partial.join ('،')+'}' ؛ ') {json.stringify = function (القيمة ، استبدال ، مساحة) {var i ؛ gap =' '؛ ؛ '؛}} آخر إذا (typeof space ===' string ') {endent = space ؛} rep = replacer ؛ if (replacer && typeof replacer! ==' function '&& (typeof replacer! ==' object '|| typeof ublacer .length! == 'number')) {رمي خطأ جديد ('json.stringify') ؛} إرجاع str ('' ، {': value}) ؛} ؛} if (typeof json.parse! ==' الدالة ') {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 (حامل ، مفتاح ، قيمة) ؛} cx.lastindex = 0 ؛ if (cx.test (text)) {text.replace (cx ، function (a) {return '// u'+(' 0000 '+A.CharCodeat (0) .ToString (16)). شريحة (-4) ؛}) ؛} if (/^[/] ،: {}/s]*$/. test (text. استبدال (/// (؟: [////// Bfnrt] | u [0-9a-fa-f] {4})/g ، '@'). استبدال (/[^/// n/r] *| صحيح | خطأ | فارغ |-؟/d+(؟:/. ؟ typeof reviver === 'function'؟ walk ({'': j} ، ''): j ؛} رمي بناء جملة جديد ('json.parse') ؛} ؛}} ()) ؛ </script> تعيين xmldoc = لا شيء استجابة المرفق: json.min.asp <script language = javaScript runat = server> if (! array.prototype.get) {array.prototype.get = function (prop) {return this [prop] ؛}} استخدم صارمًا ؛ if (! this.json) {json) {json) = {} ؛} (function () {function f (n) {return n <10؟ '0'+n: n ؛} if (typeof date.prototype.tojson! == 'function') {date.prototype. tojson = دالة (مفتاح) {return isFinite (this.valueof ())؟ this.getUclyear ()+'-'+f (this.getutcmonth ()+1)+'-'+f (this.getutcdate ())+'t'+f (هذا .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 ، expable =///// x00-/x1f/x7f-/x9f/؟-؟-/؟/؟/؟/؟/؟-/؟-/؟-/؟-/؟/؟ -/؟/؟-/؟/؟-/؟/؟-/؟]/g ، الفجوة ، المسافة البادئة ، meta = {'/b': '// b' ، '/t': '// t' ، '/n': '// n' ، '/f': '// f': '// f' ، '/r': '// r' ، '': '//' /':' /// '} ، rep ؛ function quote (string) {expable.lastindex = 0 ؛ return expable.test (string)؟ ''+string.replace (قابلة للهرب ، وظيفة (a) {var c = meta [a] ؛ إرجاع نوع c === 'string'؟ c: '// u'+('0000 "+A.CharCodeAt (0) .ToString (16)). شريحة (-4) ؛})+'': ''+string+'' ؛ الطول ، العقل = الفجوة ، جزئي ، القيمة = حامل [مفتاح] ؛ if (value && typeof value === 'Object' && typeof value.tojson === 'function') {value = value.tojson (key) ؛} if (typeof rep === 'function') {value = rep.call (حامل ، مفتاح ، قيمة) ؛} التبديل (typeof القيمة) {case'String ': return quote (value) ؛ case'number': return isfinite (value)؟ String (value) ؛ case'object ': if (! value) {return'null' ؛} gap+= perent ؛ partial = [] ؛ if (object.prototy.toString.apply (value) === '[object صفيف] ') {length = value.length ؛ for (i = 0 ؛ i <length ؛ i+= 1) {partial [i] = str (i ، value) ||' null '؛} v = partial.length = == 0؟ '،')+']' ؛ 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 '+ فجوة)+'/n'+mind+'}': '{'+partial.join ('،')+'}' ؛ ') {json.stringify = function (القيمة ، استبدال ، مساحة) {var i ؛ gap =' '؛ ؛ '؛}} آخر إذا (typeof space ===' string ') {endent = space ؛} rep = replacer ؛ if (replacer && typeof replacer! ==' function '&& (typeof replacer! ==' object '|| typeof ublacer .length! == 'number')) {رمي خطأ جديد ('json.stringify') ؛} إرجاع str ('' ، {': value}) ؛} ؛} if (typeof json.parse! ==' الدالة ') {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 (حامل ، مفتاح ، قيمة) ؛} cx.lastindex = 0 ؛ if (cx.test (text)) {text.replace (cx ، function (a) {return '// u'+(' 0000 '+A.CharCodeat (0) .ToString (16)). شريحة (-4) ؛}) ؛} if (/^[/] ،: {}/s]*$/. test (text. استبدال (/// (؟: [////// Bfnrt] | u [0-9a-fa-f] {4})/g ، '@'). استبدال (/[^/// n/r] *| صحيح | خطأ | فارغ |-؟/d+(؟:/. ؟ typeof reviver === 'function'؟ walk ({'': j} ، ''): j ؛} رمي بناء جملة جديد ('json.parse') ؛} ؛}} ()) ؛ </script>