1 Function GetHttpPage(HttpUrl,endoce) 2 If endoce = "" Then endoce = "GB2312" 3 If IsNull(HttpUrl)=True Or Len(HttpUrl)<18 Or HttpUrl="$False$" Then 4 GetHttpPage="$False$" 5 Exit Function 6 End If 7 Dim Http 8 Set Http=server.createobject("MSXML2.XMLHTTP") 9 Http.open "GET",HttpUrl,False 10 Http.Send() 11 If Http.Readystate<>4 Then 12 Set Http=Nothing 13 GetHttpPage="$False$" 14 Exit function 15 End if 16 GetHTTPPage=bytesToBSTR(Http.responseBody,endoce) 17 Set Http=Nothing 18 If Err.number<>0 then 19 Err.Clear 20 End If 21 End Function 22 23 Function BytesToBstr(Body,Cset) 24 Dim Objstream 25 Set Objstream = Server.CreateObject("adodb.stream") 26 objstream.Type = 1 27 objstream.Mode =3 28 objstream.Open 29 objstream.Write body 30 objstream.Position = 0 31 objstream.Type = 2 32 objstream.Charset = Cset 33 BytesToBstr = objstream.ReadText 34 objstream.Close 35 set objstream = nothing 36 End Function 37 38 Dim scriptCtrl 39 Function parseJSON(str) 40 If Not IsObject(scriptCtrl) Then 41 Set scriptCtrl = Server.CreateObject("MSScriptControl.ScriptControl") 42 scriptCtrl.Language = "JScript" 43 scriptCtrl.AddCode "Array.prototype.get = function(x) { return this[x]; }; var result = null;" 44 End If 45 scriptCtrl.ExecuteStatement "result = " & str & ";" 46 Set parseJSON = scriptCtrl.CodeObject.result 47 End Function 48 49 Dim json 50 51 URL = "https://www.sojson.com/api/beian/"&session("domainname") 52 json = GetHttpPage(URL,"UTF-8") 53 Set obj = parseJSON(json) 54 55 domain_type = obj.type 56 Response.Write domain_type 57 58 Set obj = Nothing
asp 獲取url 返回值 和 對json 返回值的處理