日期:2014-05-16  浏览次数:20901 次

请问ASP显示JSON格式的数据
{"weatherinfo":{"city":"南京","cityid":"101190101","temp1":"-1","temp2":"11","weather":"多云转晴","img1":"n1.gif","img2":"d0.gif","ptime":"18:00"}}


请问如何怎么用ASP的方法把下面的城市,天气显示出来?

------解决方案--------------------
<script language="JScript" runat="server">
var s = '{"weatherinfo":{"city":"南京","cityid":"101190101","temp1":"-1","temp2":"11","weather":"多云转晴","img1":"n1.gif","img2":"d0.gif","ptime":"18:00"}}';
var obj = eval("(" + s + ")");
city = obj.weatherinfo.city;
weather = obj.weatherinfo.weather;
</script>
<%
Response.Write city & " : " & weather
%>
------解决方案--------------------
<script language="JScript" runat="Server"> 
function toObject(json) {
eval("var o=" + json);
return o; 

</script> 
<% 
Dim json
json = "{""weatherinfo"":{""city"":""南京"",""cityid"":""101190101"",""temp1"":""-1"",""temp2"":""11"",""weather"":""多云转晴"",""img1"":""n1.gif"",""img2"":""d0.gif"",""ptime"":""18:00""}}"
Set json = toObject(json) 
Response.Write json.weatherinfo.city & "<br/>" 
Response.Write json.weatherinfo.weather & "<br/>"
Set json = Nothing 
%>