asp.net解析json例子

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. using System.Web.Script.Serialization;    //导入解析Json的类   
  8.   
  9.   
  10. public partial class _Default : System.Web.UI.Page  
  11. {  
  12.     protected void Page_Load(object sender, EventArgs e)  
  13.     {  
  14.         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'}]}";  
  15.         JavaScriptSerializer serializer = new JavaScriptSerializer();  
  16.         Dictionary<string, object> json = (Dictionary<string, object>)serializer.DeserializeObject(JSON);  
  17.         object[] info = (object[])json["info"];  
  18.         Dictionary<string, object> val;  
  19.         Dictionary<int, string> Objs = null;  
  20.         Dictionary<int, string> fileOldName = null;  
  21.         for (int i = 0; i < info.Length; i++)  
  22.         {  
  23.   
  24.             val = (Dictionary<string, object>)info[i];  
  25.   
  26.             foreach (KeyValuePair<string, object> str in val)  
  27.             {  
  28.                 //保存信息到 session   
  29.                 if (Session["bigfile_info"] == null)  
  30.                 {  
  31.                     Objs = new Dictionary<int, string>();  
  32.                     Session["bigfile_info"] = Objs;  
  33.                 }  
  34.                   
  35.                 if (Session["file_name"] == null)  
  36.                 {  
  37.                     fileOldName = new Dictionary<int, string>();  
  38.                     Session["file_name"] = fileOldName;  
  39.                 }  
  40.   
  41.                 if (str.Key.Equals("title"))  
  42.                 {  
  43.                     fileOldName[i + 1] = str.Value.ToString();  
  44.                 }  
  45.   
  46.                 if (str.Key.Equals("url"))  
  47.                 {  
  48.                     Objs[i + 1] = str.Value.ToString();  
  49.                 }  
  50.             }  
  51.   
  52.         }  
  53.         Session["bigfile_info"] = Objs;  
  54.         Session["file_name"] = fileOldName;  
  55.   
  56.         if (Session["file_name"] != null)  
  57.         {  
  58.             Objs = (Dictionary<int, string>)Session["file_name"];  
  59.             foreach (int i in Objs.Keys)  
  60.             {  
  61.                 lblJson.Text += Objs[i];  
  62.             }  
  63.         }  
  64.   
  65.     }  
  66. }  

转载于:https://www.cnblogs.com/Jian-Zhang/p/5120139.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值