如何将对象转换成json格式,如何将json格式数据转换成js对象

如题所述

commons-collections-3.2.jarcommons-lang.jarcommons-logging-1.1.jarezmorph-1.0.4.jar这时在测试得到了想要的结果Question q2 = new Question();q2.setId(2);q2.setDescription(descrsssss);q2.setPointInfo(pointkkkk);q2.setType(3);Question q1 = new Question();q1.setId(1);q1.setDescription(descrsssss);q1.setPointInfo(pointkkkk);q1.setType(3);JSONObject jsonObject = new JSONObject().fromObject(q2);System.out.println(jsonObject);List list = new ArrayList();list.add(q1);list.add(q2);JSONArray jsonArr= JSONArray.fromObject(list);System.out.println(jsonArr);输出:{description:descrsssss,id:2,pointInfo:pointkkkk,type:3}[{description:descrsssss,id:1,pointInfo:pointkkkk,type:3},{description:descrsssss,id:2,pointInfo:pointkkkk,type:3}]页面$.post(showQuestions?type=+type,null,callbackShowQuestions,json);这时在回调函数的参数data获得的就是json转换后的js对象数组,以下标方式便可访问数组里的相应对象信息。
温馨提示:答案为网友推荐,仅供参考
相似回答
大家正在搜