JSON,XML,JavaObject对象互相转换…
2015-12-24 10:29
561 查看
package app.json; import java.util.List; import java.util.Map; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import net.sf.json.JsonConfig; import net.sf.json.util.CycleDetectionStrategy; import net.sf.json.xml.XMLSerializer; public class JSONUtil { public static String array2json(Object[] objects){ JSONArray jsonArray = JSONArray.fromObject(objects); return jsonArray.toString(); } public static String list2json(List list){ JSONArray jsonArray = JSONArray.fromObject(list); return jsonArray.toString(); } public static String map2json(Map map){ JSONObject jsonObject = JSONObject.fromObject(map); return jsonObject.toString(); } public static String object2json(Object object){ JSONObject jsonObject = JSONObject.fromObject(object); return jsonObject.toString(); } public static String xml2json(String xml){ JSONArray jsonArray = (JSONArray) new XMLSerializer().read(xml); return jsonArray.toString(); } public static JsonConfig configJson(String[] excludes) { JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setExcludes(excludes); jsonConfig.setIgnoreDefaultExcludes(true); jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT); return jsonConfig; } }
转发至微博
转发至微博
相关文章推荐
- object is not an instance of dec…
- could not load any Objective-C class information. This will significantly reduce the quality of type
- #Objective-C 经典字典数组排序 - 省市区
- -[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object' 解决方法:
- ASP.NET MVC3更新出错:ObjectStateManager中已存在具有同一键的对象
- AsObject()转换成C#中的实体类
- OBjective-c NSThread 多线程1
- objective-c CLGeocoder 自带地图应用 路径导航
- MVVM双向绑定实现之Object.defineProperty
- eclipse工具及Object类、Scanner类
- Java Object类
- Objective-C Autorelease Pool 的实现原理
- 【Objective-C学习记录】第二十二天
- JS_funciton,object,Array
- iOS开发系列--Objective-C之KVC、KVO
- 数据类型和运算符(标识符和变量)
- Objective-C:@class和#import
- objective-c 中三种产生随机数的方法
- Objective--C UI Block 实现从后往前传值 学习笔记
- Objective-C Runtime 总结:类和对象 篇