csharp: using using System.Web.Script.Serialization read json
2023-09-11 14:19:12 时间
//先在项目中添加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;
/// returns /returns private Dictionary string, object JsonToDictionary(string jsonData) //实例化JavaScriptSerializer类的新实例 JavaScriptSerializer jss = new JavaScriptSerializer(); //将指定的 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/ //显示到界面
Myeclipse中java web.xml报错cvc-complex-type.2.3: Element web-app cannot have character [children], because the type s content type is element- only. web.xml文件添加servlet访问限制后出现如下错误: cvc-complex-type.2.3: Element web-app cannot have character [children], because the type s content type is element- only. cvc-complex-type.2.3:元素 web-app 不能包含character [children],因为该类型的内容类型是仅包含元素的。
geovindu 读者是,读之者,者之读.一沙一世界! to be is to do举世皆清我独浊,众人皆醒我独醉.俺是农民工,程序员.
/// returns /returns private Dictionary string, object JsonToDictionary(string jsonData) //实例化JavaScriptSerializer类的新实例 JavaScriptSerializer jss = new JavaScriptSerializer(); //将指定的 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/ //显示到界面
Myeclipse中java web.xml报错cvc-complex-type.2.3: Element web-app cannot have character [children], because the type s content type is element- only. web.xml文件添加servlet访问限制后出现如下错误: cvc-complex-type.2.3: Element web-app cannot have character [children], because the type s content type is element- only. cvc-complex-type.2.3:元素 web-app 不能包含character [children],因为该类型的内容类型是仅包含元素的。
geovindu 读者是,读之者,者之读.一沙一世界! to be is to do举世皆清我独浊,众人皆醒我独醉.俺是农民工,程序员.
相关文章
- ASP.NET Web Projects: web.debug.config & web.release.config
- Error 0x80070020 when you try to start a Web site in IIS 7.0
- Web测试的各个测试点,居然这么全!(文末送web测试方法大全一份)
- web后端和前端是怎么连接的?
- C#设计模式总结 C#设计模式(22)——访问者模式(Vistor Pattern) C#设计模式总结 .NET Core launch.json 简介 利用Bootstrap Paginator插件和knockout.js完成分页功能 图片在线裁剪和图片上传总结 循序渐进学.Net Core Web Api开发系列【2】:利用Swagger调试WebApi
- 【C#】对异步请求处理程序IHttpAsyncHandler的理解和分享一个易用性封装 【手记】走近科学之为什么明明实现了IEnumerable<T>的类型却不能调用LINQ扩展方法 【手记】手机网页弹出层后屏蔽底层的滑动响应 【手记】ASP.NET提示“未能创建类型”处理 【Web】一个非常简单的移动web消息框 【手记】解决EXCEL跑SQL遇“查询无法运行或数据库表无法打开...”
- java.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderListener问题解决
- Python JSON格式与字符串转换(字符串转json、json转字符串)
- 若要使他人能够在远程计算机上查看此特定错误消息的详细信息,请在位于当前 Web 应用程序根目录下的“web.config”配置文件中创建一个 <customErrors> 标记。然后应将此 <cust
- web安全day19:DNS欺骗、ARP攻击及钓鱼网站制作
- web安全day8:深入浅出掌握windows域
- PHP有关JWT(Json Web Token)的那些事
- 会员中心通过AJAX、JSON、PHP、MySql等技术实现注册和登录功能(1+X Web前端开发中级 例题)——初稿
- Pycharm使用技巧:Show as JSON(以友好的方式显示输出框的json字符串)
- 【Java】idea社区版创建 spring boot web项目
- 【Java】+【JSON】+对比两个json对象是否完全一样
- 《WEB安全渗透测试》(11)SQL注入的绕过
- 【Web漏洞探索】SQL注入漏洞
- JSON Web Token - 在Web应用间安全地传递信息
- 《HTML5移动Web开发实战》—— 1.1 移动Web设计的挑战
- SwiftUI JSON之List读取Bundle、解析、显示本地Json文件
- Context hierarchy in Spring Web MVC
- 《Web前端开发最佳实践》——第3章 标准的HTML代码3.1 验证代码是否符合标准
- nodejs基础 用http模块 搭建一个简单的web服务器 响应JSON、html
- How to set custom JsonSerializerSettings for Json.NET in MVC 4 Web API?
- flutter制作博客展示平台,现已支持 Web、macOS 应用、Android 和 iOS
- WEB前端打印使用记录
- keepalived + haproxy 实现web 双主模型的高可用负载均衡--转
- 常用基础web架构图及配置
- JSON Web Token(JWT)