当前位置: 代码迷 >> ASP >> 请教ASP显示JSON格式的数据
  详细解决方案

请教ASP显示JSON格式的数据

热度:421   发布时间:2013-12-13 00:50:19.0
请问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 
%>  
  相关解决方案