zoukankan      html  css  js  c++  java
  • Java String ,Map ,Json 相互转化

    // json
    JSON.toJSONString(json,SerializerFeature.WriteMapNullValue);
    String jsonString = JSON.toJSONString(user);  
    Map json=JSON.parseObject(jsonString);
    
    JSONObject jsonparm=new JSONObject(map);
    String json=jsonparm.toString();
    
    //前提是String的格式是map或json类型的
    
    //String 转Json
    
     JSONObject  jasonObject = JSONObject.fromObject(str);
    
    //String 转Map
    
    JSONObject  jasonObject = JSONObject.fromObject(str);
    Map map = (Map)jasonObject;
    
    
    
    
    //map 转json
    Map<String, Object> map = new HashMap<String, Object>();
    JSONObject jsonparm=new JSONObject(map);// 可以是map  或者实体类对象
    String json=jsonparm.toString();
    
    //string 直接转json
    String json=contListRequest.getBindCont().toString();
    JSONObject parseObject = JSON.parseObject(json);
    
    //string 转json
    String jsonStr = JSON.toJSONString(result);  
    Map mapresult=JSON.parseObject(jsonStr);
    
    JSONObject parseObject = JSON.parseObject(result);
    
    
    /*JSONObject jsonObject = JSONObject.parseObject(json);
                String data = jsonObject.get("item").toString();
                ComUser comuser= JSON.parseObject(data,ComUser.class);
                UseUser user  = JSON.parseObject(data, UseUser.class);
                user.setComUser(comuser);
                String jsondata=JsonMapper.toDateJSON(user);*/
                //UseUser user  = JSON.parseObject(parseObject.toJSONString(), UseUser.class);
  • 相关阅读:
    mysql 主从复制
    通过git-bash 批量管理VMware虚拟机
    MySQL基础
    lnmp架构
    搭建yum仓库服务器
    什什么是集群?么是分布式?
    nginx介绍1
    网络抓包工具 wireshark 入门教程
    DNS原理总结及其解析过程详解
    PetaPoco中使用Exists
  • 原文地址:https://www.cnblogs.com/xkoko/p/9377921.html
Copyright © 2011-2022 走看看