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. public partial class _Default : System.Web.UI.Page
  9. {
  10. protected void Page_Load(object sender, EventArgs e)
  11. {
  12. 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‘}]}";
  13. JavaScriptSerializer serializer = new JavaScriptSerializer();
  14. Dictionary<string, object> json = (Dictionary<string, object>)serializer.DeserializeObject(JSON);
  15. object[] info = (object[])json["info"];
  16. Dictionary<string, object> val;
  17. Dictionary<int, string> Objs = null;
  18. Dictionary<int, string> fileOldName = null;
  19. for (int i = 0; i < info.Length; i++)
  20. {
  21. val = (Dictionary<string, object>)info[i];
  22. foreach (KeyValuePair<string, object> str in val)
  23. {
  24. //保存信息到 session
  25. if (Session["bigfile_info"] == null)
  26. {
  27. Objs = new Dictionary<int, string>();
  28. Session["bigfile_info"] = Objs;
  29. }
  30. if (Session["file_name"] == null)
  31. {
  32. fileOldName = new Dictionary<int, string>();
  33. Session["file_name"] = fileOldName;
  34. }
  35. if (str.Key.Equals("title"))
  36. {
  37. fileOldName[i + 1] = str.Value.ToString();
  38. }
  39. if (str.Key.Equals("url"))
  40. {
  41. Objs[i + 1] = str.Value.ToString();
  42. }
  43. }
  44. }
  45. Session["bigfile_info"] = Objs;
  46. Session["file_name"] = fileOldName;
  47. if (Session["file_name"] != null)
  48. {
  49. Objs = (Dictionary<int, string>)Session["file_name"];
  50. foreach (int i in Objs.Keys)
  51. {
  52. lblJson.Text += Objs[i];
  53. }
  54. }
  55. }
  56. }
时间: 2025-01-20 06:36:14

asp.net解析json例子的相关文章

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 {    

Asp.net 解析json

Asp.net Json数据解析的一种思路 http://www.cnblogs.com/scy251147/p/3317366.html http://tools.wx6.org/json2csharp/

ASP( VBScript ) 解析 JSON

<script language="jscript" runat="server"> Array.prototype.get = function(x) { return this[x]; }; function parseJSON(strJSON) { return eval("(" + strJSON + ")"); } </script> <% Dim json, obj json = &q

Gson解析json数据(转)

一. www.json.org这是JSON的官方网站. 首先,我,我们需要在code.google.com/p/google-gson/downloads/list下载JSON的jar包,解析后把gson-1.6.jar文件导入到你那个需要解析的项目中去. 解析JSON例子,如下: 1. 这是Json数据,"[{\"name\":\"Michael\",\"age\":20},{\"name\":\"Mik

ASP.NET与json对象互转

这两天写这个xml跟json的读写,心累啊,也不是很理解,请大家多指教 首先来个热身菜做一个简单的解析json 在script里写一个简单的弹窗效果 <script> //script里简单的解析json var json = '{"name": "学生","info": [{ "count": "1", "stuname": "张三 ", "s

ASP.NET万能JSON解析器

ASP.NET万能JSON解析器 概念介绍还是先简单说说Json的一些例子吧.注意,以下概念是我自己定义的,可以参考.net里面的TYPE的模型设计如果有争议,欢迎提出来探讨!1.最简单:{"total":0} total就是值,值是数值,等于02. 复杂点{"total":0,"data":{"377149574" : 1}}total是值,data是对象,这个对象包含了"377149574"这个值,等于

使用QtScript库解析Json数组例子

本文转载自:http://blog.sina.com.cn/s/blog_671732440100uwxh.html 使用qtscipt库解析json数组首先在工程文件中加 QT        += script 然后头文件加 #include <QtScript> 然后解析 QString str = "{\"name\":\"xiaotang\", \"age\":\"23\", \"chi

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

JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析和生成.它基于JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999的一个子集. JSON采用完全独立于语言的文本格式,但是也使用了类似于C语言家族的习惯.这些特性使JSON成为理想的数据交换语言. JSON建构于两种结构: 1.“名称/值”对的集合(A collec

《项目经验》--通过js获取前台数据向一般处理程序传递Json数据,并解析Json数据,将前台传来的Json数据写入数据库表中

  先看一下我要实现的功能界面:   这个界面的功能在图中已有展现,课程分配(教师教授哪门课程)在之前的页面中已做好.这个页面主要实现的是授课,即给老师教授的课程分配学生.此页面实现功能的步骤已在页面中有所体现,这里不再赘述,此篇文章主要介绍:我是如何通过js从前台获取数据,然后通过ajax技术向后台一般处理程序传递JSON,后台又是如何获取传来的JSON,并对JSON数据转换,然后将转换后的数据写入数据库的! 介绍这些步骤实现前,先说说自己的辛酸:絮叨辛酸,是因为为了实现这个功能,我真的用了很