经典ASP - 解析JSON XMLHTTP返回 [英] Classic ASP - Parse JSON XMLHTTP Return
问题描述
我无法找到解析我从XMLHTTP得到回报的好办法。返回的是JSON。
I am having trouble finding a good way to parse the return I'm getting from XMLHTTP. The return is JSON.
ASP code用于获取JSON:
ASP Code used to GET JSON:
<%@ Language=VBScript %>
<%
Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP.6.0")
xmlhttp.open "GET", "http://someip:8080/Publisher/Titles/Paging/0,0,tc?output=json", 0
xmlhttp.send ""
Response.AddHeader "Content-Type", "application/json;charset=UTF-8"
Response.Charset = "UTF-8"
pageReturn = xmlhttp.responseText
Set xmlhttp = Nothing
response.write pageReturn
%>
返回的JSON
Returned JSON
{
"Titles": {
"resultCount": 37886,
"moreResources": true
}
}
我需要显示RESULTCOUNT到屏幕上的刚值。任何帮助将大大AP preciated。
I need to display just the value of "resultCount" to the screen. Any help would be greatly appreciated.
推荐答案
您可以看看aspjson与VBScript中处理JSON
You can look at aspjson for handling JSON with VBScript
的http://$c$c.google.com/p/aspjson/
您还可以使用JavaScript作为传统的ASP服务器端脚本语言,这将涉及您重写的Javascript服务器的HTTP请求,但它会使页面的JSON部分容易多了。
You can also use Javascript as your classic asp server side scripting language, which would involve you rewriting your server http request in Javascript, but it would make the json part of the page much easier.
您甚至可以使用VBS和JS在同一个页面,例如:
You can even use VBS and JS in the same page, eg
<%@ Language=javascript %>
<script language="VBScript" runat="server">
Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP.6.0")
xmlhttp.open "GET", "http://someip:8080/Publisher/Titles/Paging/0,0,tc?output=json", 0
xmlhttp.send ""
Response.AddHeader "Content-Type", "application/json;charset=UTF-8"
Response.Charset = "UTF-8"
pageReturn = xmlhttp.responseText
Set xmlhttp = Nothing
</script>
<% var resultcount = pageReturn.Titles.resultCount;
var moreresources = pageReturn.Titles.moreResources;
%>
<html>
<body>
<%=resultcount%>, <%=moreresources%>
</body>
</html>
这篇关于经典ASP - 解析JSON XMLHTTP返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!