asp 获取url 返回值 和 对json 返回值的处理

时间:2023-12-26 09:53:55
     Function GetHttpPage(HttpUrl,endoce)
If endoce = "" Then endoce = "GB2312"
If IsNull(HttpUrl)=True Or Len(HttpUrl)<18 Or HttpUrl="$False$" Then
GetHttpPage="$False$"
Exit Function
End If
Dim Http
Set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",HttpUrl,False
Http.Send()
If Http.Readystate<>4 Then
Set Http=Nothing
GetHttpPage="$False$"
Exit function
End if
GetHTTPPage=bytesToBSTR(Http.responseBody,endoce)
Set Http=Nothing
If Err.number<>0 then
Err.Clear
End If
End Function Function BytesToBstr(Body,Cset)
Dim Objstream
Set Objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function Dim scriptCtrl
Function parseJSON(str)
If Not IsObject(scriptCtrl) Then
Set scriptCtrl = Server.CreateObject("MSScriptControl.ScriptControl")
scriptCtrl.Language = "JScript"
scriptCtrl.AddCode "Array.prototype.get = function(x) { return this[x]; }; var result = null;"
End If
scriptCtrl.ExecuteStatement "result = " & str & ";"
Set parseJSON = scriptCtrl.CodeObject.result
End Function Dim json URL = "https://www.sojson.com/api/beian/"&session("domainname")
json = GetHttpPage(URL,"UTF-8")
Set obj = parseJSON(json) domain_type = obj.type
Response.Write domain_type Set obj = Nothing

asp 获取url 返回值 和 对json 返回值的处理