日期:2014-05-17  浏览次数:20515 次

我得到了一个josn格式字符串,想要分析它并得到想要的值要怎么做
{"weatherinfo":{"city":"北京","cityid":"101010100","temp":"25","WD":"西南风","WS":"3级","SD":"59%","WSE":"3","time":"16:00","isRadar":"1","Radar":"JC_RADAR_AZ9010_JB"}}

比如我得到上面字符串,我想要得到的结果是:
北京:101010100
温度:25度
时间:16:00

我.net 如何实现啊,谁能给我一个具体的小例子,非常感谢

------解决方案--------------------
C# code

String jsonString =
                "{\"weatherinfo\":{\"city\":\"北京\",\"cityid\":\"101010100\",\"temp\":\"25\",\"WD\":\"西南风\",\"WS\":\"3级\",\"SD\":\"59%\",\"WSE\":\"3\",\"time\":\"16:00\",\"isRadar\":\"1\",\"Radar\":\"JC_RADAR_AZ9010_JB\"}}";
            var scriptSerializer = new JavaScriptSerializer();
            var weatherinfo = scriptSerializer.Deserialize<Dictionary<String, Dictionary<String, String>>>(jsonString);
            var detail = weatherinfo[""];
            //detail["city"];//取得北京。同样获取其他信息。

------解决方案--------------------
可以用JavaScript,比如json赋值给res
JScript code

var sJson=eval(res);
for(var i=0;i<sJson.length;i++)
{
 document.getElementById("div1").innerHTML +=
"sJson[i].city:sJson[i].cityid"+
"温度:sJson[i].temp"+
"时间:sJson[i].time";
}