2014-09-23 29 views
-2

我的情況,我的web服務給我發通知,其中包括檢索使用JSON有效載荷的Android

{ 
    "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推送通知.....

+0

'我在JSON有一個初學者的知識'那麼你必須擴大知識... – Selvin 2014-09-23 09:08:52

+0

請留下那些有趣的評論.....如果可能幫助我... – karthik 2014-09-23 09:13:36

+1

似乎不可能(幫助你)由於您在提問前懶得使用http://google.com,因此這裏有很多問題的重複...請在進行調查之前做一些調查 – Selvin 2014-09-23 09:14:54

回答

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... 
} 
+0

爲什麼?你爲什麼回答?它是重複的,然後標記爲重複 – Selvin 2014-09-23 09:16:21

+1

爲什麼你downvoted?如果你不能幫助別人...不要粗魯.. – 2014-09-23 09:17:33

+0

我downvoted,因爲我不喜歡名譽研磨的問題,已經有一個答案在這裏 – Selvin 2014-09-23 09:24:24