using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//先在项目中添加System.Web.Extensions引用.net 3.5
using System.Web.Script.Serialization;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Text;
using System.Net; namespace JSONFromCS
{
public partial class WebForm3 : System.Web.UI.Page
{
/// <summary>
/// 将json数据反序列化为Dictionary
///http://www.weather.com.cn/static/html/legend.shtml 天气图示
/// </summary>
/// <param name="jsonData">json数据</param>
/// <returns></returns>
private Dictionary<string, object> JsonToDictionary(string jsonData)
{
//实例化JavaScriptSerializer类的新实例
JavaScriptSerializer jss = new JavaScriptSerializer();
try
{
//将指定的 JSON 字符串转换为 Dictionary<string, object> 类型的对象
return jss.Deserialize<Dictionary<string, object>>(jsonData);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{ string url = "http://www.weather.com.cn/data/cityinfo/101280601.html";
WebClient wc = new WebClient();
wc.Encoding = System.Text.Encoding.UTF8;//定义对象语言
string json = wc.DownloadString(url);
//string json = "{\"weatherinfo\":{\"city\":\"深圳\",\"cityid\":\"101280601\",\"temp\":\"32\",\"WD\":\"西南风\",\"WS\":\"4级\",\"SD\":\"68%\",\"WSE\":\"4\",\"time\":\"16:40\",\"isRadar\":\"1\",\"Radar\":\"JC_RADAR_AZ9755_JB\"}}";
StringBuilder strb = new StringBuilder();
Dictionary<string, object> dic = JsonToDictionary(json);//将Json数据转成dictionary格式
Dictionary<string, object> dataSet = (Dictionary<string, object>)dic["weatherinfo"];
//使用KeyValuePair遍历数据
foreach (KeyValuePair<string, object> item in dataSet)
{ strb.Append(item.Key + ":" + item.Value + "<br/>");//显示到界面 } Response.Write(strb.ToString());
}
}
}

csharp: using using System.Web.Script.Serialization read json的更多相关文章

  1. ASP.NET 使用 System.Web.Script.Serialization 解析 JSON (转)

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析和生成.它基于JavaScript Programming Langu ...

  2. 参考C# 使用 System.Web.Script.Serialization 解析 JSON

    参考C# 使用 System.Web.Script.Serialization 解析 JSON 使用json需要引用到System.Web.Script.Serialization.习惯在解决方案右键 ...

  3. C# 使用 System.Web.Script.Serialization 解析 JSON

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析和生成.它基于JavaScript Programming Langu ...

  4. 在.net2.0下使用System.Web.Script.Serialization;

    最近,在弄json字符串转为对象.需要添加这个引用System.Web.Script.Serialization;因为版本必须是dotnet2.0的原因,发现很多解决方案不适合自己.故使用这种解决办法 ...

  5. System.Web.Script.Serialization引用找不到的问题

    之前在项目中要使用JavascriptSerializer这个类,需要引入System.Web.Script.Serialization命名空间,但是在添加引用中找不到这个命名空间,后来才得知Syst ...

  6. using System.Web.Script.Serialization

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析和生成.它基于JavaScript Programming Langu ...

  7. System.Web.Script.Serialization的引用

    解决方案: 找到C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0 ==>System.Web.Extensions.d ...

  8. The type or namespace name 'Script' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

    应该说是 .net4 的bug,没有所谓的 System.Web.Extensions.dll 库文件,需要将项目的 Target Framework修改为 3.5版本,才能加载System.Web. ...

  9. "System.Web" 中不存在类型或命名空间

    System.Web”中不存在类型或命名空间名称script  /找不到System.Web.Extensions.dll引用 添加引用就行了...“添加引用→.Net→System.Web.Ente ...

随机推荐

  1. 前端获取指定cookie

    前端获取指定cookie的值 function getCookie(cookiename){ var name = cookiename + "="; var cs = docum ...

  2. python全栈开发_day6_元组,字典,集合

    一:元组    1)定义    元组:有序,可以按索引取值,不可变,但是可以修改元组里面可变数据的数据内容. res = (1,2,3,4,3,2,1) 2)内置方法和使用 res.count(1) ...

  3. UVALive - 6436、HYSBZ - 2435 (dfs)

    这两道题都是用简单dfs解的,主要是熟悉回溯过程就能做,据说用bfs也能做 道路修建(HYSBZ - 2435) 在 W 星球上有n 个国家.为了各自国家的经济发展,他们决定在各个国家 之间建设双向道 ...

  4. 创建djangoapp

    1.python3 manage.py startapp goods 2.startapp users 3.启动django服务器 # make new migrationspython3 manag ...

  5. mouseover和mouseenter闪烁的问题

    span标签绑定mouseover/mouseout事件,显示/隐藏一个信息框div 该div下没有任何子元素 悬停上去一直闪烁,改成mouseenter也没用. 照成的原因是:悬停上去信息框div盖 ...

  6. MongoDB wiredTiger存储引擎下的存储方式LSM和B-Tree比较

    前段时间做拦截件监控的时候把拦截件生命期存入mongodb,因生命期有各种变化,因此对此表的更新写操作非常多,老大给我看了一篇文章,才知道mongodb已经支持lsm存储方式了. 原文如连接:http ...

  7. Comparison of Symbolic Deep Learning Frameworks

    http://blog.revolutionanalytics.com/2016/08/deep-learning-part-1.html Deep Learning Part 1: Comparis ...

  8. Java框架-mybatis01查询单个数据

    1.什么是mybatis? mybatis是一个基于Java的持久层框架. 2.持久化:数据从瞬时状态变为持久状态. 3.持久层:完成持久化工作的代码块.---dao 4.Mybatis是帮助程序员将 ...

  9. 宜人贷项目里-----正则匹配input输入月份规则

    在标签上可以直接进行校验如下,如果只调数字键盘type=number不好用可以用type=tel <input name="creditDate" oninput=" ...

  10. wDatepicker97的用法(点击事件联动)

    1.在使用wdatepicker的时候用户需要选中然后联动其他的下拉,看了插件的文档,研究了一下 <input type="text" id="date" ...