string 转JSONObject

/*"{
"code": 801,
"message": "没有返回结果",
"result": {
"code": 802,
"message": "红包生效时间不能小于当前时间,失败",
"result": {}
}
}}*/

import net.sf.json.JSONArray; //用于集合或数组
import net.sf.json.JSONObject; //用于对象,
string 转object 
JSONObject json_test = JSONObject.fromObject(result);
String message=json_test.get("message").toString();


<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<!--json包-->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20150729</version>
</dependency>

posted on 2017-06-12 17:41  积累学习  阅读(623)  评论(0编辑  收藏  举报

导航