String字符串如何转为json格式

如果当前字符串为String objectStr="{"Phone":"17717636102",  +
""Gender":"1"  +
""EmployeeCode":""}";

打印出来:

{"Phone":"17717636102", "Gender":"1","EmployeeCode":""}

转为json对象:

JSONObject jsonObject=new JSONObject(objectStr);

这时候里面就是key value键值对了

jsonObject.has("Phone")//判断key值是否存在   

jsonObject.getString("Phone")//取对应的value值
jsonObject.put("name","张三");//放key value键值对
 
 
原文地址:https://www.cnblogs.com/yxj808/p/13428214.html