ASP.net解析JSON例子
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Script.Serialization; //导入解析Json的类 public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string JSON = "{'info':[{'title':'list1','url':'/upload/209/20120814163339890.png'},{'title':'离职申请表','url':'/upload/209/20120814163339968.xls'},{'title':'申请表','url':'/upload/209/20120814163340046.doc'},{'title':'室内','url':'/upload/209/20120814163340156.jpg'},{'title':'心电图','url':'/upload/209/20120814163340218.gif'},{'title':'新建 文本文档','url':'/upload/209/20120814163340281.txt'}]}";
JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, object> json = (Dictionary<string, object>)serializer.DeserializeObject(JSON);
object[] info = (object[])json["info"];
Dictionary<string, object> val;
Dictionary<int, string> Objs = null;
Dictionary<int, string> fileOldName = null;
for (int i = 0; i < info.Length; i++)
{ val = (Dictionary<string, object>)info[i]; foreach (KeyValuePair<string, object> str in val)
{
//保存信息到 session
if (Session["bigfile_info"] == null)
{
Objs = new Dictionary<int, string>();
Session["bigfile_info"] = Objs;
} if (Session["file_name"] == null)
{
fileOldName = new Dictionary<int, string>();
Session["file_name"] = fileOldName;
} if (str.Key.Equals("title"))
{
fileOldName[i + 1] = str.Value.ToString();
} if (str.Key.Equals("url"))
{
Objs[i + 1] = str.Value.ToString();
}
} }
Session["bigfile_info"] = Objs;
Session["file_name"] = fileOldName; if (Session["file_name"] != null)
{
Objs = (Dictionary<int, string>)Session["file_name"];
foreach (int i in Objs.Keys)
{
lblJson.Text += Objs[i];
}
} }
}
ASP.net解析JSON例子的更多相关文章
- ASP.net解析JSON
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- Asp.net 解析json
Asp.net Json数据解析的一种思路 http://www.cnblogs.com/scy251147/p/3317366.html http://tools.wx6.org/json2csha ...
- Asp.Net解析json字符串
方法一: using LitJson; string json= "{...........}"; JsonData jdData = JsonMapper.ToObject(js ...
- ASP( VBScript ) 解析 JSON
<script language="jscript" runat="server"> Array.prototype.get = function( ...
- Gson解析json数据(转)
一. www.json.org这是JSON的官方网站. 首先,我,我们需要在code.google.com/p/google-gson/downloads/list下载JSON的jar包,解析后把gs ...
- JackSon解析json字符串
JackSon解析json字符串 原文:http://blog.csdn.net/java_huashan/article/details/9353903 概述 jackson解析json例子 准备工 ...
- ASP.NET与json对象互转
这两天写这个xml跟json的读写,心累啊,也不是很理解,请大家多指教 首先来个热身菜做一个简单的解析json 在script里写一个简单的弹窗效果 <script> //script里简 ...
- ASP.NET 使用 System.Web.Script.Serialization 解析 JSON (转)
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析和生成.它基于JavaScript Programming Langu ...
- asp.net中json格式化及在js中解析json
类: public class UploadDocumentItem { public UploadDocumentItem() { } public string DocMuid { get; se ...
随机推荐
- 全选,不选,反选js
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name ...
- HDU5831
Rikka with Parenthesis II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- JAVA6开发WebService (二)——JAX-WS例子
转载自http://wuhongyu.iteye.com/blog/807836 上一篇写了个最简单的小例子,只是为了说明JAVA6开发Web Service很方便,这一篇稍微深入一点,写个稍微有点代 ...
- centos 安装haproxy 1.6.3
yum install libtermcap-devel ncurses-devel libevent-devel readline-devel gcc gcc-c++ pcre pcre-devel ...
- php for循环嵌套
<?php //2.打印一个50*50的 'o' 的正方形方整, 使用for的嵌套 // oooooo // oooooo // oooooo //for循环嵌套 ...
- Struts基础详解
1.web.xml配置: <filter> <filter-name>Struts2</filter-name> <filter-class> org. ...
- JDK+MyEclipse+Tomcat的配置(修改Tomcat 6.x的端口)
修改tomcat的端口,在conf目录里的server.xml文件 例如想将端口修改为8080则将port的值修改为8081,其余值不变 通过Tomcat服务器访问 想通过浏览器访问这个页面,需要在T ...
- IOS第二天多线程-01-延时执行
**********延时执行 #import "HMViewController.h" @interface HMViewController () @end @implement ...
- PG, Pool之间的一些数量关系
先说一下我的环境: Ceph cluster中包含6台OSD节点 (osd.0 - 5), 一共有10个Pool (0 - 9), 这些Pool共享了144个PG (这个数字是所有Pool的PG_SI ...
- ArcGIS Server 创建站点失败
前期解决方案中部分解决方法汇总:①安装Server时创建的ArcGIS Server Account (操作系统级别用户,默认用户名arcgis)对创建站点时新建的站点目录arcgisserver文件 ...