fastjson:string轉json對象或json數組以及它們的取值方法

引入MAVEN依賴

<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.47</version>
        </dependency>

String轉JSONObject

JSONObject jsonObject = JSONObject.parseObject ("{name:'xxx',age:'18'}");

獲取裏面的值

jsonObject.getString ("name")

輸出:xxx 

String轉JSONArray

JSONArray jsonArray = JSONObject.parseArray ("[{name:'xxx',age:'18'},{name:'iii',age:'19'}]");

獲取裏面的值

jsonArray.getJSONObject (1).getString ("name");

輸出:iii

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章