首页 > 代码库 > Java String TO Json
Java String TO Json
ServiceImpl :
@Override public List<?> courseAd(String KEYNAME, String KEYCODE) { String str = "{‘courseAdUrl‘:‘http://xy.baoai.com/curriculum/detail/24‘,‘courseAdID‘:‘1001‘}"; String str1 = "{‘courseAdUrl‘:‘http://xy.baoai.com/curriculum/detail/22‘,‘courseAdID‘:‘1002‘}"; String str2 = "{‘courseAdUrl‘:‘http://xy.baoai.com/curriculum/detail/10‘,‘courseAdID‘:‘1003‘}"; List<Object> list = new ArrayList<>(); list.add(str); list.add(str1); list.add(str2); JSONArray jsonArray = JSONArray.fromObject(list); return jsonArray; }
Controller
@PostMapping("/courseAd") @ResponseBody public ResultModel courseAd(String KEYNAME, String KEYCODE){ List<?> list = courseService.courseAd(KEYNAME, KEYCODE); return ResultModel.build(1, "success", list); }
返回JSON数据
{"status":1,"msg":"success","data":[{"courseAdUrl":"http://xy.baoai.com/curriculum/detail/24","courseAdID":"1001"},{"courseAdUrl":"http://xy.baoai.com/curriculum/detail/22","courseAdID":"1002"},{"courseAdUrl":"http://xy.baoai.com/curriculum/detail/10","courseAdID":"1003"}],"success":null}
Java String TO Json
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。