解析如何從服務器解析JSONObject
。我從服務器作爲如何使用JSON在Android的
{
"status": "success",
"authKey": "$2y$13$fg2dFdy7KbSsZP.WIddETOYxOCtJHtFwwGDTJudQ6w7hQcH5vGm16"
}
解析如何從服務器解析JSONObject
。我從服務器作爲如何使用JSON在Android的
{
"status": "success",
"authKey": "$2y$13$fg2dFdy7KbSsZP.WIddETOYxOCtJHtFwwGDTJudQ6w7hQcH5vGm16"
}
嘗試下面是解決
try{
JSONObject object = new JSONObject(response)
String status = oject.getString("status")
String authKey = oject.getString("authKey")
}catch(Exception e){ e.printStackTrace();}
希望它會幫助你。
JSON對象包含像地圖鍵/值對。密鑰是字符串 ,值是JSON類型。鍵和值由逗號分隔 。
你可以用這種方式
String getStatus = "",authKey="";
try {
JSONObject reader = new JSONObject("{"status":"success","authKey":"$2y$13$fg2dFdy7KbSsZP.WIddETOYxOCtJHtFwwGDTJudQ6w7hQcH5vGm16"}"); //Put your Json String
getStatus = reader.getString("status");
authKey = reader.getString("authKey");
}
catch (JSONException e) {
e.printStackTrace();
}
try {
JSONObject jsonObject = new JSONObject(response.toString());
String status = jsonObject.optString("status");
String authKey = jsonObject.optString("authKey");
} catch (JSONException e) {
e.printStackTrace();
}
try {
JSONObject jsonObj =new JSONObject("your response string");
String status = jsonObj.optString("status");
String authKey = jsonObj.optString("authKey");
} catch (JSONException e) { e.printStackTrace(); }
JSONObject jsonObject = new JSONObject(response);
String status= jsonObject.getString("status");
String authKey = jsonObject.getString("authKey");
什麼是響應變量在這裏...? – Gopibilla
這是你的迴應字符串。 –
怎麼可以?我有我的迴應在這裏... – Gopibilla
你得到這個事情 - { 「狀態」: 「成功」, 「AUTHKEY」: 「$ 2Y $ $ 13 fg2dFdy7KbSsZP.WIddETOYxOCtJHtFwwGDTJudQ6w7hQcH5vGm16」 }。----是反應都你明白不? – Shane
謝謝,我會檢查它 – Gopibilla