I am trying to get JSON data from an api which generates the user name and password but I am failing to do so, please help
Asked
Active
Viewed 112 times
0
Faysal Ahmed
- 7,003
- 5
- 27
- 47
Ayan Bhattacharjee
- 77
- 2
- 10
-
1Please add your code as text and not images – Tamir Abutbul Mar 03 '19 at 20:46
2 Answers
0
Your API returns JSON Object instead of JSONArray.
Check difference between those two : JSON Object vs JSONArray
Though you can work with JSONObject too, just do below:
String value = jsonObject.getString("key")
In case of you are using Volley, then by default Volley returns success response by parsing it in JSONObject. So jsonObject would be replaced by response.
Swr7der
- 839
- 9
- 28
0
Your API returns JSON Object instead of JSONArray. Parse your response directly in JSONObject instead of JSONArray and retrieve id and password from it.
JSONObject jsonObject= new JSONObject(response);
String id=jsonObject.getString("u_name");
String passworf=jsonObject.getString("u_pass");
Ved
- 1,033
- 14
- 28