1. 程式人生 > >Java json字串轉json物件

Java json字串轉json物件

需要匯入的jar包

commons-beanutils-1.8.0.jar  

commons-collections-3.2.1.jar

commons-lang-2.5.jar

commons-logging-1.1.1.jar

ezmorph-1.0.6.jar

json-lib-2.4-jdk15.jar

需要新增的依賴:

importnet.sf.json.JSONObject;

json字串:

data = {"USERID":1,"PASSWORD":"1","USERNAME":"admin","RNAME":"","PHONEMOBILE":"","PHOTO":"","EMAIL":"","SEX":-1,"STATE":-1,"ADDRESS":-1}

JSONObject jsStr = JSONObject.fromObject(data);
String s = jsStr.get("USERNAME").toString();