zoukankan      html  css  js  c++  java
  • 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. }  
  • 相关阅读:
    【npm】mac下node环境搭建
    pair求解迷宫的最短路径(bfs)
    dos窗口启动关闭Mysql
    二维差分模板
    一维差分模板
    DOS命令
    迷宫搜索dfs实现
    DFS 迷宫问题
    BFS广搜解决迷宫问题(跟着B站大佬手撸)
    蓝桥杯省赛模拟赛
  • 原文地址:https://www.cnblogs.com/Jian-Zhang/p/5120139.html
Copyright © 2011-2022 走看看