Reputation: 41
I want to parsing JSON in android using volleylibrary for login.In Login activity,send two parameters(username,password) via post and response like below.
parameters :
username
password
for success:
{
"status": 1,
"message": "successfully login" ,
"result": [
{
"name": "abc",
"email": "[email protected]",
"Img": "http://img.com/img.png"
}
]
}
for login:
{
"status": 0,
"message": "email or password doesn’t exist"
}
Upvotes: 0
Views: 737
Reputation: 31
It is how to do it.
public void onResponse(JSONObject response) {
try {
int status = response.getInt("status");
if (status == 1) {
String message = response.getString("message");
JSONArray jsonArray = response.getJSONArray("result");
JSONObject jsonObject = jsonArray.getJSONObject(0);
String name = jsonObject.getString("name");
String email = jsonObject.getString("email");
String imgLink = jsonObject.getString("Img");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
Upvotes: 2