asp 获取远程 json 乱码 ,请问如何处理?谢谢!

life360 2018-10-01 03:47:10

<%
function getHTTPPage(url)
dim Http
set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
if err.number<>0 then err.Clear
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%>
<%


txtURL="http://dt.jctytech.com/stock.php?u=test&market=le&type=stock"




sText = getHTTPPage(txtURL)

Set FileObject=Server.CreateObject("Scripting.FileSystemObject")
filename="aaaaaaa.txt"
Set openFile=FileObject.OpenTextfile(server.mapPath(filename),2,true) 'true为不存在自行建立
openFile.writeline(sText)
Set OpenFile=nothing
set objstream = nothing





%>
...全文
636 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
horizon_zpy 2018-10-02
  • 打赏
  • 举报
回复
<%
function getHTTPPage(url)
dim Http
set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
rem getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
getHTTPPage=Http.responseText

set http=nothing
if err.number<>0 then err.Clear
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%>
<%


txtURL="http://dt.jctytech.com/stock.php?u=test&market=le&type=stock"




sText = getHTTPPage(txtURL)
Response.charset="gbk"
Response.Write sText
Set FileObject=Server.CreateObject("Scripting.FileSystemObject")
filename="aaaaaaa.txt"
Set openFile=FileObject.OpenTextfile(server.mapPath(filename),2,true) 'true为不存在自行建立
openFile.writeline(sText)
Set OpenFile=nothing
set objstream = nothing





%>
hookee 2018-10-02
  • 打赏
  • 举报
回复
这个不是字符集转码的问题。 返回的数据是gzip压缩过的, 要找一个zip组件(最好是内存中直接解压字符串的)解压一下就行了。
孟子E章 2018-10-01
  • 打赏
  • 举报
回复
你可以使用utf-8试试啊
getHTTPPage=bytesToBSTR(Http.responseBody,"utf-8")

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧