JAVA-JSON解析-JSONObject

总结归纳一些常用的 JSONObject 使用,仅供参考。

1 .  net.sf.json-lib 解析JSON

    pom.xml  :

        <dependency>  

            <groupId>net.sf.json-lib</groupId>  

            <artifactId>json-lib</artifactId>  

            <version>2.2.3</version>  

            <classifier>jdk15</classifier><!-- 指定jdk版本 -->  

        </dependency> 

    * String 转 json    --- 字符串 转 json

    JSONObject json = JSONObject.fromObject(string);

    

2.

    * List 转 JSONString  -- List 转 json字符串

    JSONObject.toJSONString(list)  //  import com.alibaba.fastjson.JSONObject;

    * JSONString 转 List  ---    json 字符串 转 List 
 

(List<CLASS>)JSONArray.parseArray(listStr,CLASS.class);//import com.alibaba.fastjson.JSONArray; 需要强转 

3. 

JSON转 bean;

Bean bean = JSONObject.parseObject(iterator.next().getString("content"), Bean.class);

bean 转 JSON:

JSONObject.toJSONString(bean);

猜你喜欢

转载自blog.csdn.net/weixin_37618127/article/details/80328430