使用JSON PAYLOAD android从通知中检索值

时间:2014-09-23 09:03:50

标签: android jsonp xtify

我处于这种情况,我的网络服务向我发送包含

的通知
{
    "apiKey": "xxxxx-xxx-xxx-xxxx-xxxxxxx",
    "appKey": "xxxxx-xxx-xxx-xxxx-xxxxxxx",
    "sendAll": true,
    "content": {
        "subject": "Test Lottery",
        "message": "Notification Msg",
        "action": {
            "type": "DEFAULT",
            "data": "url|intent|...",
            "labe": "label"
        },
        "payload": "{'uid':'1','type':'LD'}",
        "sound": "default.caf",
        "badge": "+1"
    }
}

点击顶部显示的通知,我需要获取uidtype

我正在使用Xtify进行推送通知.....

1 个答案:

答案 0 :(得分:0)

试试这个..

String JSON ="YOUR JSON RESULT STRING";
try {
    JSONObject jsonresult = new JSONObject(JSON);

    String apiKey= jsonresult.getString("apiKey");
    String appKey= jsonresult.getString("appKey");
    boolean sendAll= jsonresult.getBoolean("sendAll");

    JSONObject contentObject = jsonresult.getJSONObject("content");
    String subject= jsonresult.getString("subject");
    String message= jsonresult.getString("message");
    String sound= jsonresult.getString("sound");
    String badge= jsonresult.getString("badge");

    JSONObject actionObject = jsonresult.getJSONObject("action");

    String type= jsonresult.getString("type");
    String data= jsonresult.getString("data");
    String labe= jsonresult.getString("labe");

    JSONObject payloadObject = jsonresult.getJSONObject("payload");
    // do your code..

    }
} catch (JSONException e) {
    e.printStackTrace();
    //catching exceptions if any...
}