首页天道酬勤json字符串转jsonobject对象,json如何转java对象

json字符串转jsonobject对象,json如何转java对象

张世龙 05-06 04:22 110次浏览

依赖于pom.xml

ependencygroupidcom.Alibaba/groupidartifactidfastjson/artifactidversion1.2. 73/version/dependency 3358 www.Sina

stringjsontemplate1=' {\' taskids\' : [\' c 072 a9 a8- 2275-11e B- a135-d83 bbfb 92464\',\ ' ea52374; ea5b 5522232322222323232323232 ' ee1 ab34 e-2274-11e B- a135-d83 bbfb 92464\',\ ' formpropoper ] jsonobjectparamsbody=JSON object.parse object (jsobject JSONArrayTaskids=(JSONArray ) Paramsbody.get ) (Taskids ); JSONarrayprocessids=(JSONarray ) paramsbody.get ) (processids ); JSONobjectParams=(JSONobject ) Paramsbody.get ) (formproperty ); for(intI=0; itaskIds.size (; I({stringtaskid=taskids.get(I ) )!=null? taskids.get(I ).toString ) ) : '; system.out.println(taskid ); } system.out.println (params.tostring ();1.json字符串转换JSONObject/JSONArray

stringjsonuser=' {\n '\' name\' :\'肖战\ ',\n'\sex\'3360\'男人\ ',\ n '\' age用户参数系统. out.println (parse user object;2.json字符串转换为对象

Map resultMap=new HashMap (; resultmap.put('name ',' zhangsan ' ); 结果地图. put (age,) 18 ); //方法转换为json字符串,然后转换为json对象string JSON=JSON.tojsonstring (result map ); jsonobjectjsonobject=JSON.parse object (JSON; 系统. out.println (JSON object; //方法2 stringx=直接转换JSON object.tojsonstring (result map )的system.out.println(x;

javaobject对象转换,java对象转成json格式