JSON序列化与反序列化JavaScript
2015-12-10 14:57
726 查看
一、JSON序列化JavaScript
1.首先创建一个JavaScriptSettings对象
2.序列化JavaScript
3.运行结果
![](http://img.blog.csdn.net/20151210145706522)
二、反序列化JavaScript
1.反序列化JavaScriptSettings
2.反序列后的结果
![](http://img.blog.csdn.net/20151210150621859)
JSON源代码下载地址:http://download.csdn.net/detail/lovegonghui/9342751
1.首先创建一个JavaScriptSettings对象
using System; using System.Collections.Generic; using System.Linq; using System.Text; using GongHuiNewtonsoft.Json.Linq; namespace JSONDemo { public class JavaScriptSettings { public JRaw OnLoadFunction { get; set; } public JRaw OnUnloadFunction { get; set; } } }
2.序列化JavaScript
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using GongHuiNewtonsoft.Json; using GongHuiNewtonsoft.Json.Linq; namespace JSONDemo { class Program { static void Main(string[] args) { JavaScriptSettings settings = new JavaScriptSettings { OnLoadFunction = new JRaw("OnLoad"), OnUnloadFunction = new JRaw("function(e){alert(e);}") }; string json = JsonConvert.SerializeObject(settings, Formatting.Indented); Console.WriteLine(json); } } }
3.运行结果
二、反序列化JavaScript
1.反序列化JavaScriptSettings
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using GongHuiNewtonsoft.Json; using GongHuiNewtonsoft.Json.Linq; namespace JSONDemo { class Program { static void Main(string[] args) { string json = @" { 'OnLoadFunction':'OnLoad', 'OnUnloadFunction':'function(e){alert(e);}' }"; JavaScriptSettings js = JsonConvert.DeserializeObject<JavaScriptSettings>(json); Console.WriteLine(js.OnLoadFunction); Console.WriteLine(js.OnUnloadFunction); } } }
2.反序列后的结果
JSON源代码下载地址:http://download.csdn.net/detail/lovegonghui/9342751
相关文章推荐
- 通过 JSON 字符串来创建对象&通过eval()方法生成原生Javascript对象
- <html5+css3+js>一个audio note界面
- 初识backbone.js(1)
- Javascript常见操作
- JSON 中的毫秒时间( LONG) ,转换成年月日
- JavaScript 闭包
- js--在页面元素上(移动到或获取焦点)、鼠标离开(或失去焦点)
- gulpfile.js 中的坑--注入篇(gulp-inject,gulp-wiredep)
- js取json数据笔记
- 解决方案:Jboss修改jsp需要重启才生效
- JSON序列化与反序列化DataSet
- 【JavaScript 从零开始】 语言核心部分----可选的分号
- js unicode编码与解码
- js操作数组函数实例小结
- window.localtion.href深入理解
- JS获得URL参数
- JS模态窗口返回值兼容问题解决方案
- sso跨域写cookie的一段js脚本
- 对 Sea.js 进行配置 seajs.config
- ElasticSearch.js