转化
Java与其他语言编写的程序进行tcp/ip socket通讯时,通讯内容一般都转换成byte数组型:
1、将字符转换成byte数组
     String  str = "罗长";
     byte[] sb = str.getBytes();
2、将byte数组转换成字符
     byte[] b={(byte)0xB8,(byte)0xDF,(byte)0xCB,(byte)0xD9}; 
     String str= new String (b);
3、为了方便字符的加减操作,通常以16进制字符替代普通字符与byte数组进行相互转换
对象与字符串
对象转字符串 String str =JSON.toJSONString( infoDo);
字符串转对象 InfoDo infoDo = JSON.parseObject(strInfoDo,InfoDo.class);
对象集合与字符串
对象集合转字符串 String users = JSON.toJSONString(users);
字符串转对象集合 List<User> userList = JSON.parseArray(userString,User.class);
字符串与JSONObject
字符串转Json对象 JSONObject jsonObject = JSONObject.parseObject(jsonString);
JSONObject jsonString = JSONObject.parseObject(str);
Json对象转字符串 String jsonString = jsonObject.toJSONString();
map与字符串
字符串转map: JSONObject jsonObject = JSONObject.parseObject(str);
Map<String,Object> map=(Map<String,Object>) jsonObject;
map转字符串 String jsonString = JSON.toJSONString(map);
Map与json对象
map转json对象 Map<String,Object> map =new HashMap<>();
map.put("age", 24);
map.put("name","cool_summer");
JSONObject json = new JSONObject(map);
json对象转map Map<String,Object> map = (Map<String,Object>) jsonObject ;
 
                    
                     
                    
                 
                    
                
 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号