用google包吧String转成map,转成对象


    
        com.google.code.gson
        gson
        2.2.4
    

   JSONObject json = JSONObject.parseObject(content);

Gson gson = new Gson();
        Map map = new HashMap();
        map = gson.fromJson(jsonString, map.getClass());#关键
        String goodsid=(String) map.get("goods_id");
        System.out.println("map的值为:"+goodsid);
  XcxMessageVo xcxVo = gson.fromJson(content,XcxMessageVo.class);

 

读取文件转成String:

 public String getRecmCont(String filePath) {
        Object obj = null;
        String path = getRequest().getSession().getServletContext().getRealPath("") + "/clt2/" + filePath + "/index.htm";
        logClass.info(" read File serviceNum:=" + serviceNum + " ,path:= " + path);
        try {
            obj = FileUtils.readFileToString(new File(path), "utf-8");
        } catch (IOException e) {
            e.printStackTrace();
        }

        if (obj == null) {
            return "";
        }
        return (String) obj;
    }

 

你可能感兴趣的:(后端)