JSONBuilder - C#扩展版
比较简单的C#版JSONBuilder:(.net 2.0) - 只有两个文件:JSONBuilder.cs , JSONBuilderDelegates.cs - 不用考虑对象嵌套输出格式的匹配问题 - 自动字符串转义 - 支持常见数据类型、以及常用的数据结构如: 任意数组,ArrayList,List<object> ,Hashtable,Dictionary<string,object> 等 - 支持任意扩展,通过注册自定义类型的转换方法(参看JSONBuilderTest.cs 和 JSONBuilderDelegates.cs)可支持任意类型的json字符串转换 - 支持自定义的包含 public string toJSON() 的对象的输出(忽略大小写) - 带有测试的VS2005完整项目 - 可任意使用修改(只要包含原作者信息) //转换回调函数接口 --> JSONBuilder.cs public delegate string ToJSONDelegate(object value, bool useSingleQuote); //-->JSONBuilderTest.cs 比如: //demo custom class public class CustomClass { public string name = "Hu Changwei"; public string nickName = "koqiui"; public string email = "koqiui@163.com"; public string gender = "male"; public bool married = true; public DateTime birthDate = new DateTime(1978, 5, 21); } //demo custom json convertor public static string fromCustomClass(object value, bool useSingleQuote) { if (value == null) { return JSONBuilder.NullStr; } if (value.GetType() == typeof(CustomClass)) { CustomClass objValue = value as CustomClass; JSONBuilder jb = new JSONBuilder(useSingleQuote); jb.startObject(); // jb.add("Author", objValue.name); jb.add("nickname", objValue.nickName); jb.add("email", objValue.email); jb.add("married", objValue.married); jb.add("birthdate", objValue.birthDate); // jb.endObject(); return jb.toJSON(); } return JSONBuilder.NullStr; } [Test] public void test_customConvertor() { JSONBuilder.setJSONConvertor(typeof(CustomClass), new ToJSONDelegate(fromCustomClass)); JSONBuilder jb = new JSONBuilder(); jb.addValue(new CustomClass()); Console.WriteLine(jb.toJSON()); }
- 1
- yjso57922014-01-09很简单适合初学
- jcins2015-07-18简单易懂。
- 粉丝: 8
- 资源: 20
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 《认识计算机桌面》教案.doc
- 《软件工程》期末考试参考题及答案.doc
- 《软件工程》期末考试及答案.doc
- 《软件工程》经典考试例题复习试题-重点知识点(含答案)(良心出品必属精品).doc
- 《软件工程》经典考试例题复习题-重点知识点(含答案)(良心出品必属精品).docx
- 《软件工程》考试及答案A卷B卷.doc
- python-ldap-3.4.4-cp311-cp311-win-amd64.whl
- 【推荐】logistic分析(可编辑修改).ppt
- 基于opencv的dnn模块实现Yolo-Fastest的目标检测python源码+模型+说明(高分项目).zip
- 使用Python调用微信本地ocr服务.zip