asp如何接收 POST json解析
1、传统的ASP与ASP之间post提交json可以用:
json=cstr(request.form)
来获取得到的json代码
2、实际上,如果是java或php提交过来的话,用request.form可能得到的就是空值,最稳妥的办法是根据二进制流得到数据,具体操作如下:
3、2个页面,第一个页面假设为:funtion.asp
代码如下:
<%
function bytes2bstr(vin)
dim bytesstream,stringreturn
set bytesstream = server.CreateObject("adodb.stream")
bytesstream.type = 2
bytesstream.open
bytesstream.writeText vin
bytesstream.position = 0
bytesstream.charset = "utf-8"'或者gb2312
bytesstream.position = 2
stringreturn = bytesstream.readtext
bytesstream.close
set bytesstream = nothing
bytes2bstr = stringreturn
end function
%>
4、第二个页面,假设为demo.asp,代码如下:
<!--#include file="funtion.asp"-->
<%
getpostjson=Request.TotalBytes '得到字节数
if getpostjson=0 then
response.Write("json null")
response.End()
end if
readjson=Request.BinaryRead(getpostjson) '二进制方式来读取客户端使用POST传送方法所传递的数据
json = bytes2bstr(readjson) '二进制转化
response.write(json)
%>
5、字符串解析:
Set jsonobj=getJSONObject(json)