2016-12-27 21 views
1

解析如何從服務器解析JSONObject。我從服務器作爲如何使用JSON在Android的

響應
{ 
    "status": "success", 
    "authKey": "$2y$13$fg2dFdy7KbSsZP.WIddETOYxOCtJHtFwwGDTJudQ6w7hQcH5vGm16" 
} 

回答

-1

嘗試下面是解決

try{ 
    JSONObject object = new JSONObject(response) 
    String status = oject.getString("status") 
    String authKey = oject.getString("authKey") 
}catch(Exception e){ e.printStackTrace();} 

希望它會幫助你。

+0

怎麼可以?我有我的迴應在這裏... – Gopibilla

+0

你得到這個事情 - { 「狀態」: 「成功」, 「AUTHKEY」: 「$ 2Y $ $ 13 fg2dFdy7KbSsZP.WIddETOYxOCtJHtFwwGDTJudQ6w7hQcH5vGm16」 }。----是反應都你明白不? – Shane

+0

謝謝,我會檢查它 – Gopibilla

1

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(); 
      } 
+0

如何獲得JSON字符串爲 「Your_Json」 的地方 – Gopibilla

+0

@Gopibilla展示你的工作吧。 –

+0

http://amogaa.com/nimaatri/frontend/web/?r=site/cust-login&username=mohan&password=Test1234 – Gopibilla

0
try { 
    JSONObject jsonObject = new JSONObject(response.toString()); 

    String status = jsonObject.optString("status"); 
    String authKey = jsonObject.optString("authKey"); 
} catch (JSONException e) { 
    e.printStackTrace(); 
} 
0
try { 
    JSONObject jsonObj =new JSONObject("your response string"); 
    String status = jsonObj.optString("status"); 
    String authKey = jsonObj.optString("authKey"); 
} catch (JSONException e) { e.printStackTrace(); } 
+0

我怎麼把我的響應字符串從Web視圖編寫 – Gopibilla

+0

後您試圖代碼。 –

+0

http://amogaa.com/nimaatri/frontend/web/?r=site/cust-login&username=mohan&password=Test1234這是鏈接,我想從這個鏈接獲得AUTHKEY我怎樣才能得到它 – Gopibilla

-1
JSONObject jsonObject = new JSONObject(response); 
String status= jsonObject.getString("status"); 
String authKey = jsonObject.getString("authKey"); 
+0

什麼是響應變量在這裏...? – Gopibilla

+0

這是你的迴應字符串。 –