using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; using LitJson;
using System.Data;
using System.Collections;
using System.Web.Script.Serialization; public class Person
{ public string Name { get; set; }
public int Age { get; set; }
} public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Response.AddHeader("Content-Type", "application/json;");
//Response.ContentType = "application/json";
//Response.ContentEncoding = System.Text.Encoding.UTF8;
#region LitJson练习
JsonData jd = new JsonData();
jd["sada"] = "dsad";
jd["www"] = ;
JsonData jr = new JsonData();
jr["m"] = jd;//可以赋值,也可以赋值jsondata
jr["time"] = DateTime.Now.ToLocalTime().ToString();
jr["qqq"] = ;
jr["asda"] = "dawd";
string json = JsonMapper.ToJson(jr);//②步,jsondata不是json字符串,还要把jsondata序列化,
Response.Write(json);
// {
// "m": {
// "sada": "dsad",
// "www": 123
// },
// "time": "2015-04-19 14:38:41",
// "qqq": 567,
// "asda": "dawd"
// }
#endregion
#region ArrayList,List<>--->[]随意是数字,字符串
//ArrayList arr1 = new ArrayList();
//arr1.Add("dasda");
//arr1.Add("mmm");
//arr1.Add(99999);
//string rdt = JsonMapper.ToJson(arr1);//["dasda","mmm",99999]
//Response.Write(rdt); //List<int> list1 = new List<int>();
//list1.Add(5);
//list1.Add(8);
//string rmt = JsonMapper.ToJson(list1);//[5,8]
//Response.Write(rmt); //List<string> list = new List<string>();
//list.Add("xiaoming");
//list.Add("xiaohong");
//string rat = JsonMapper.ToJson(list);//["xiaoming","xiaohong"]数组
//Response.Write(rat);
#endregion
#region 键值对-->{}字典Hashtable,Dictionary<>,序列化成json,唯一要求键要为字符串 //Hashtable has = new Hashtable();
//has.Add("1", "sada");
//has.Add("5", 99);
//string str = JsonMapper.ToJson(has);
//Response.Write(str); //Dictionary<string, int> dic1 = new Dictionary<string, int>();
//dic1.Add("1", 5);
//dic1.Add("3", 9);
//var json = JsonMapper.ToJson(dic1);
//Response.Write(json); //Dictionary<string, string> dic = new Dictionary<string, string>();//
//dic.Add("xiaohong", "28");
//dic.Add("xiaolan", "22");
//string json = JsonMapper.ToJson(dic);//{"xiaohong":"28","xiaolan":"22"}
//Response.Write(json);
#endregion
#region 无法将类型为“system.int32”的对象强制转换为类型“system.string”。
//Hashtable has = new Hashtable();
//has.Add(1, "sada");
//has.Add(5, "sadjdi");
//string str = JsonMapper.ToJson(has);//无法将类型为“System.Int32”的对象强制转换为类型“System.String”
//Response.Write(str); //Dictionary<int, string> dic = new Dictionary<int, string>();//
//dic.Add(1, "dawd");
//dic.Add(9, "www");
//string json = JsonMapper.ToJson(dic);
//Response.Write(json); //Dictionary<int, int> dic1 = new Dictionary<int, int>();
//dic1.Add(1, 5);
//dic1.Add(3, 9);
//var json = JsonMapper.ToJson(dic1);
//Response.Write(json);//无法将类型为“System.Int32”的对象强制转换为类型“System.String”
#endregion
#region JavaScriptSerializer,内置序列化的一种方式,同上,键为字符串
//JavaScriptSerializer javascriptSerializer = new JavaScriptSerializer();
//var json = javascriptSerializer.Serialize(dic1);
//Response.Write(json);
#endregion
#region 普通类-->{},JsonMapper.ToJson(),JavaScriptSerializer和序列化普通类
//Person p = new Person();
//p.Name = "like";
//p.Age = 24;
//string ret = JsonMapper.ToJson(p);//{"Name":"like","Age":24} //Person p1 = new Person();
//p.Name = "like";
//p.Age = 24;
//JavaScriptSerializer javascriptSerializer = new JavaScriptSerializer();
//var json = javascriptSerializer.Serialize(p1);
//Response.Write(json);
#endregion
}
}

全部代码

对一个集合,要求不序列化完,对其中的几项序列化。这时内置序列化对象就不方便。这是用LitJson[“key”]=value;方便。

List<RechargeM> list = RecBL.GetTB(Gid);
foreach (var item in list)
{
JsonData jd = new JsonData();
jd["ID"] = Tools.GetString(item.Id);
jd["Num"] = item.cRech_Num;
jd["Money"] = item.mRech_Money;
jd["Date"] = Tools.GetString(item.dRech_Date);
row.Add(jd);
}
Jlist["RechargeLis"] = row;

LitJson JavaScriptSerializer的更多相关文章

  1. JavaScriptSerializer 序列化json 时间格式

    利用JavaScriptSerializer 序列化json 时间格式,得到的DateTime值值显示为“/Date(700000+0500)/”形式的JSON字符串,显然要进行转换 1.利用字符串直 ...

  2. JavaScriptSerializer使用条件

    JavaScriptSerializer使用条件:需先引用组件:System.Web.Extensions 类全称:System.Web.Script.Serialization.JavaScript ...

  3. 在引用KindEditor编辑器时,运行时出现以下错误:错误46 找不到类型或命名空间名称“LitJson”(是否缺少 using 指令或程序集引用?)

    将asp.net下bin文件夹下的文件LitJSON.dll拷贝到工程的bin目录下,并在工程中添加引用 在后台加入: using LitJson;

  4. 关于litJson的System.InvalidCastException

    最近在做一个Unity3D的项目,用到了litJson库, 它比JavaScript里的JSON解析更加严格, 有时候解析数据的时候会出现类型不对. 比如说 {"data":12} ...

  5. XML数据 JSON数据 LitJSON 数据 的编写和解析 小结

    用XML生成如下数据<?xml version="1.0"encoding="UTF-8"?><Transform name="My ...

  6. JSON 序列化和反序列化——JavaScriptSerializer实现

    一. JavaScriptSerializer 类由异步通信层内部使用,用于序列化和反序列化在浏览器和 Web 服务器之间传递的数据.您无法访问序列化程序的此实例.但是,此类公开了公共 API.因此, ...

  7. JavaScriptSerializer序列化时间处理

    JavaScriptSerializer序列化时间后会把时间序列化成N进制的鬼数据,于是查了下质料坐下记录 假设list = News List<Text>(){new Text(){id ...

  8. JavaScriptSerializer 中的匿名类型 转json

    二:JavaScriptSerializer 中的匿名类型 这个类型我想大家都清楚,不过性能更高的方式应该是用JsonConvert吧,但这个不是本篇讨论的话题,我们重点来看看匿名类型的Json序列化 ...

  9. asp.net JavaScriptSerializer实现序列化和反序列化

    通过JavaScriptSerializer来实现.它的名字空间为:System.Web.Script.Serialization 如果要使用它,还须添加 System.Web.Extensions库 ...

随机推荐

  1. matplotlib y轴标注显示不全以及subplot调整的问题

    matplotlib y轴标注显示不全以及subplot调整的问题 问题: 我想在y轴显示的标注太长,想把它变成两行显示,发现生成的图形只显示的第二行的字,把第一行的字挤出去了 想要的是显示两行这样子 ...

  2. sklearn的画图

    from sklearn.metrics import roc_curve fpr, tpr, thresholds=roc_curve(y_train_5, y_scores) fpr, tpr & ...

  3. Tomcat 8 中的startup.bat

    1. bat文件 批处理文件,在DOS和Windows(任意版本)的系统中,bat文件是可执行文件 2. startup.bat 中涉及的bat语法 2.1 @. echo. echo off @ec ...

  4. JSP include 指令

    1. 创建test5.jsp test5_1.jsp test5_2.jsp test5_1.jsp <%@ page import="java.util.*" %> ...

  5. ES(2): Build ES Cluster on Azure VM

    目录: 系统环境准备 安装ES集群 安装Kibana 安装x-pack 安装head 系统环境准备 参见: HDP2.4安装(二):Centos7配置 修改network: 修改hosts: 配置ss ...

  6. 学习 ASP.NET MVC

    http://www.cnblogs.com/gaoweipeng/category/203080.html http://blog.csdn.net/liu_ben_qian/article/det ...

  7. 启动ECLIPSE时,提示failed to create the java virtual machine

    修改eclipse.ini中的-XX:MaxPermSize=256M 这一项的原始值是512M.

  8. 惠普(HP)战66 Pro G1 - 批量GHOST[Win10专业版 ] (UEFI)

    笔记本型号:惠普(HP)战66 Pro G1 14英寸轻薄笔记本电脑(i5-8250U 8G 256G PCIe SSD+500G 标压MX150 2G独显)银色 需求: 公司一共采购10台笔记本,需 ...

  9. 一小时入门webpack

    webpack现在已经成为了大众化的项目必要脚手架,基本上现在的很多项目都需要webpack,由于webpack的出现glup和grunt已经完败,今天我们来说一下webpack如何使用. 首先我们需 ...

  10. hdu 1278 逃离迷宫

    逃离迷宫 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...