当前位置: 动力学知识库 > 问答 > 编程问答 >

how to get given JSON value?

问题描述:

i am trying to get this given Jso value, but "data" value not get.

{

"result": {

"success": true,

"data": {

"eid": "mcXRukleFJkd2O2xZvE$5w",

"points_earned": 0,

"post_sharing_params": {

"message": "ajgdakalhajgajabakjkaaahkakakaha. \r\n#LifeAtCapgemini "

}

}

}

}

  • I create one function to access this value, but "data" Json object value is not assign my model object, so please tell me proper solution.

    try {

    JSONObject resultJsonObject = new JSONObject(response.toString());

    if (resultJsonObject.length() != 0 && resultJsonObject != null) {

    try {

    mFeedActionCustomModel.setFeed_success(BaseParser.optString(resultJsonObject, "success"));

    try {

    JSONObject dataJsonObject = resultJsonObject.getJSONObject("data");

    if (dataJsonObject.length() != 0 && dataJsonObject != null) {

    mFeedActionCustomModel.setEid(BaseParser.optString(dataJsonObject, "eid"));

    mFeedActionCustomModel.setPointsEarned(BaseParser.optString(dataJsonObject, "points_earned"));

    try {

    JSONObject postSharingParamsJsonObject = dataJsonObject.optJSONObject("post_sharing_params");

    if (postSharingParamsJsonObject.length() != 0 && postSharingParamsJsonObject != null) {

    mFeedActionCustomModel.setFeed_message(BaseParser.optString(postSharingParamsJsonObject, "message"));

    }

    } catch (Exception e) {

    }

    }

    } catch (Exception e) {

    }

    } catch (Exception e) {

    }

    }

    } catch (Exception e) {

    }

网友答案:

Quite simply:

JSONObject dataJsonObject = resultJsonObject.getJSONObject("result").getJSONObject("data");

You haven't browsed the result attribute yet (where data is the child of).

分享给朋友:
您可能感兴趣的文章:
随机阅读: