汇编编程环境-MASM6.15版下载
2009-10-23 17:20
381 查看
1.数组转换为json字符串(用JSONArray)
2.list转换为json字符串(用JSONArray)
3.Map转换为json字符串(用JSONObject)
4.普通java对象转为json字符串
user对象:
注意:和map的结果一样的
5.复杂的java对象转为json字符串(对象中包含list和map)
UserScores对象:
{"age":"23","name":"junxie","scores":["100","98"],"scores2":{"math":"90","chinese":"80"}}
注意:scores为list的生成结果,scores2为map的生成结果
6.json字符串转为普通对象
注意:先生成jsonObject,再调用静态方法JSONObject.toBean(jsonObject, beanClass)
7.json字符串转为复杂对象(对象中含有list,map或者其他对象)
UserScores@739495b8
[100, 98]
{math=90, chinese=80}
注意:如果要解析成复杂对象时,应该先建立Map,放入所有的复杂对象类型,最后调用方法
JSONObject.toBean(jsonObject, beanClass, classMap) 该classMap则放入所有复杂对象的map
String array[] = new String[]{"one","two","three"}; JSONArray jsonArray= JSONArray.fromObject(array); System.out.println(jsonArray);结果:["one","two","three"]
2.list转换为json字符串(用JSONArray)
List list = new ArrayList(); list.add("1"); list.add("2"); list.add("3"); JSONArray jsonArray = JSONArray.fromObject(list); System.out.println(jsonArray);结果:["1","2","3"]
3.Map转换为json字符串(用JSONObject)
Map map = new HashMap<String,String>(); map.put("name", "junxie"); map.put("age", "23"); map.put("county", "china"); JSONObject jsonObject = JSONObject.fromObject(map); System.out.println(jsonObject);结果:{"county":"china","age":"23","name":"junxie"}
4.普通java对象转为json字符串
user对象:
public class User { public String name; public String age; public String country; public User(){} public User(String name,String age,String country){ this.name = name; this.age = age; this.country = country; } //省略get和set方法 }
User user = new User("junxie","23","china"); JSONObject jsonObject = JSONObject.fromObject(user); System.out.println(jsonObject);结果:{"age":"23","country":"china","name":"junxie"}
注意:和map的结果一样的
5.复杂的java对象转为json字符串(对象中包含list和map)
UserScores对象:
public class UserScores{ private List scores; //list private String name; private String age; private Map scores2; //map .....//省略get和set方法 }
List scores = new ArrayList(); scores.add("100"); scores.add("98"); //组装list Map scores2 = new HashMap<String, Integer>(); scores2.put("chinese", "80"); scores2.put("math", "90"); //组装map UserScores useScores = new UserScores(); useScores.setAge("23"); useScores.setName("junxie"); useScores.setScores(scores); useScores.setScores2(scores2); JSONObject jsonObject = JSONObject.fromObject(useScores); System.out.println(jsonObject);结果:
{"age":"23","name":"junxie","scores":["100","98"],"scores2":{"math":"90","chinese":"80"}}
注意:scores为list的生成结果,scores2为map的生成结果
6.json字符串转为普通对象
String jsonString = "{age:'23',country:'china',name:'junxie'}"; JSONObject jsonObject = JSONObject.fromObject(jsonString); User user = (User)JSONObject.toBean(jsonObject,User.class); System.out.println(user.getName());结果:打印的name为 junxie
注意:先生成jsonObject,再调用静态方法JSONObject.toBean(jsonObject, beanClass)
7.json字符串转为复杂对象(对象中含有list,map或者其他对象)
String jsonList = "{age:'23',name:'junxie',scores:['100','98'],scores2:{math:'90',chinese:'80'}}"; //待解析的json字符串 Map map = new HashMap(); map.put("scores", String.class); //复杂对象list map.put("scores2", Map.class); //复杂对象map (可以有其他的子对象等) JSONObject jsonObject = JSONObject.fromObject(jsonList); UserScores userScores= (UserScores)JSONObject.toBean(jsonObject, UserScores.class, map); //注意该方法中要放入之前建立的map System.out.println(userScores); List<String> scores = userScores.getScores(); System.out.println(scores); Map scores2 = userScores.getScores2(); System.out.println(scores2);结果:
UserScores@739495b8
[100, 98]
{math=90, chinese=80}
注意:如果要解析成复杂对象时,应该先建立Map,放入所有的复杂对象类型,最后调用方法
JSONObject.toBean(jsonObject, beanClass, classMap) 该classMap则放入所有复杂对象的map
相关文章推荐
- 32位汇编编程模板--使用masm6.15环境
- 构建汇编编程环境(MASM32V10)
- Win10 + MASM32 + EditPlus 汇编语言编程环境设置
- GVIM: 《手把手教你把Vim改装成一个IDE编程环境 Ver: 0.7》下载
- ARM汇编编程基础(四) -- ADS开发环境的使用
- Java编程环境配置的常用软件下载JDK1.4+Tomcat5.0
- ==masm汇编不同环境的写法==
- 《手把手教你把Vim改装成一个IDE编程环境 Ver: 0.7》下载
- Spark编程环境搭建-超详细代码(可下载)
- Reachability 网络编程总结(解析数据,下载文件,确认网络环境)
- 《手把手教你把Vim改装成一个IDE编程环境 Ver: 0.7》下载
- 汇编编程环境的搭建
- 在Linux环境下(Ubuntu)编写MASM汇编程序
- 适用于所有主流Java编程环境的图表库TeeChart for Java v3.2017.0622发布[附下载]
- MASM汇编环境配置
- 用VC6构建MASM32汇编的编程环境
- Spark编程环境搭建-超详细代码(可下载)
- 用Visual Studio.net 2010构建MASM编程环境(转载jinsonghu专栏)
- 用VS2010构建MASM的编程环境
- 适用于所有主流Java编程环境的图表库TeeChart for Java v3.2017.0622发布[附下载]