经典ASP - 解析JSON XMLHTTP返回

时间:2014-12-08 22:47:04

标签: json asp-classic xmlhttprequest

我无法找到一种解析我从XMLHTTP获得的回报的好方法。返回是JSON。

ASP代码用于获取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”的值。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

您可以查看aspjson以使用VBScript处理JSON

http://code.google.com/p/aspjson/

您还可以使用Javascript作为经典的asp服务器端脚本语言,这将涉及您在Javascript中重写服务器http请求,但它会使页面的json部分更容易。

您甚至可以在同一页面中使用VBS和JS,例如

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