天天看點

用google包吧String轉成map,轉成對象

<!-- 配置gson -->
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.2.4</version>
    </dependency>      
JSONObject json = JSONObject.parseObject(content);

Gson gson = new Gson();
        Map<String, Object> map = new HashMap<String, Object>();
        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);      
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;
    }