java fastjson处理json

//json字符串变json对象
json对象 = JSON.parseObject(json字符串,json对象);
//json数组变json对象
LIST<json对象> xx =JSON.parseArray(json数组,json对象) ;
//json对象转json字符串
json字符串 = toJSONString(json对象);
 <!--fastjson-->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>fastjson</artifactId>
      <version>1.1.41</version>
    </dependency>
/**
     * 批量置为有效
     * @Param
     * @Return
     * */
    @ResponseBody
    @RequestMapping(value = "/effectivemore", method = RequestMethod.POST)//POST
    public JsonResponse toEffectiveMore(@Validated String params) throws Exception{
        JsonResponse data = null;
        List<Effective> list = JSON.parseArray(params,Effective.class);
        int line = 0;
        for (Effective eff:list){
             line +=  editorResource.effective(eff);
        }
        if (line>=list.size()){
            data = new JsonResponse(ResponseCode.RESPONSE_SUCCESS, "置为有效成功", line);
        }else {
            data = new JsonResponse(ResponseCode.RESPONSE_ERROR, "置为有效失败", line);
        }
        return data;
    }

  String jsons = "[{\"f_catalog_id\":551,\"f_catalog_name\":\"科大讯飞海绵听书\",\"f_catalog_parentid\":0},{\"f_catalog_id\":552,\"f_catalog_name\":\"小说\",\"f_catalog_parentid\":551},{\"f_catalog_id\":553,\"f_catalog_name\":\"评书\",\"f_catalog_parentid\":551},{\"f_catalog_id\":554,\"f_catalog_name\":\"逻辑思维\",\"f_catalog_parentid\":551},{\"f_catalog_id\":558,\"f_catalog_name\":\"地道战\",\"f_catalog_parentid\":553}]";
        List<JsonClass> list = JSON.parseArray(jsons,JsonClass.class);
        //查找f_catalog_name为 “地道战” 的f_catalog_id 558
        for (JsonClass js:list){
            if(js.getF_catalog_name().equals("百团大战")){
                System.out.println(js.getF_catalog_id());
            }
        }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容