android解析多重嵌套json數據

android解析多重嵌套json數據

android端獲取的數據如下:
這裏寫圖片描述


JAVA代碼

獲取json數組裏的某個值


    String articleID;
    String username;
    String address;
    String avatar;
    String title;
    String image;
    String content;
    String like;
    String message;
    String date;
    String browse;
    /**
     * 獲取json數組裏的指定值
     * @param jsonArray1 json源數據
     * @param position 二維數組中的第幾個一維數組
     */
    public void getJson(JsonArray jsonArray1,int position){

                JSONObject user;
                JSONObject imgObj;

                JSONArray jsonArray2 = jsonArray1.getJSONArray(position); //獲取一維數組
                JSONObject json = jsonArray2.getJSONObject(0);
                user = jsonArray2.getJSONObject(1);

                articleID = json.get("id").toString();
                username = user.get("name").toString();
                address = json.get("address").toString();
                avatar = user.get("image").toString();
                title = json.get("title").toString();
                content = json.get("content").toString();
                like = json.get("like").toString();
                message = json.get("message").toString();
                date = json.get("date").toString();
                browse = json.get("browse").toString();

                String articleImgBean = json.get("articleImgBean").toString();
                if (articleImgBean.length() > 0) {
                    imgObj = new JSONObject(articleImgBean);
                    image = imgObj.get("path").toString();
                }
    }

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