life360
2018-10-01 07:41
采纳率: 0%
浏览 721

asp 获取远程 json 乱码

<%
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

%>

文件是乱码的,请问如何解决?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • blownewbee 2018-10-01 07:58

    getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
    你确认是GB2312么,试试看别的编码

    点赞 打赏 评论
  • weixin_42171151 2018-10-01 12:38

    response.write sc4Json.Eval("jsonObject.name")&"
    "
    response.write sc4Json.Eval("jsonObject.content[1].id")

    点赞 打赏 评论

相关推荐 更多相似问题