经典 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.
用于获取 JSON 的 ASP 代码:
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
{
"Titles": {
"resultCount": 37886,
"moreResources": true
}
}
我只需要在屏幕上显示resultCount"的值.任何帮助将不胜感激.
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://code.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屋!