使用fastJson 處理json字符串數據獲取對象和集合等操作

Maven座標:fastjson 具體的版本根據各人情況而定 但是個人介意還是採用使用量多的

		<dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.56</version>
        </dependency>
:Request是一個對象 可以根據情況來作出相應的返回值 根據具體的業務來決定
public RequestJson JsonToRequestObject(String json) {
        RequestJson requestJson=new RequestJson();
        JSONObject jsonObject = JSONObject.parseObject(json);
        JSONObject data = jsonObject.getJSONObject("data");
        JSONObject verificationData= jsonObject.getJSONObject("data").getJSONObject("verifications");
        requestJson.setOrderID(data.get("orderID").toString());
        JSONArray jsonArray = JSONArray.parseArray(verificationData.getString("verification"));
        for (int i=0;i<jsonArray.size();i++){
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            Object approveMethod = jsonObject1.get("approveMethod");
            Object code = jsonObject1.get("code");
            Object fQDN = jsonObject1.get("fQDN");
            requestJson.setApproveMethod(approveMethod.toString());
            requestJson.setCode(code.toString());
            requestJson.setfQDN(fQDN.toString());
        }
        return requestJson;
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章