kehinde hussein
kehinde hussein

Reputation: 11

how to get String data from jsonobject

I have a json array like below and want to get firstname and lastname from form it any help form guzs please

{
    "message": "Verification",
    "data": {
        "accountStatus": "OPEN",
        "firstName": "Y",
        "lastName": "SHITTU",
        "customerType": "SUD",
        "invoicePeriod": 1,
        "dueDate": "2017-09-09T00:00:00+01:00",
        "customerNumber": 309804811
    },
    "status": "success"
}

Upvotes: 0

Views: 5331

Answers (2)

fida1989
fida1989

Reputation: 3249

//First create JSON object from the json...    
JSONObject obj = new JSONObject(" .... ");
//Then get firstname and lastname as string...
String firstName = obj.getJSONObject("data").getString("firstName");
String lastName = obj.getJSONObject("data").getString("lastName");

Upvotes: 3

Bob
Bob

Reputation: 13865

I would suggest you reading Json Parsing first. Just Googled and got this tutorial.

Parser for your response in the question: (response is the Json you have as String type)

    JsonObject json = new JsonObject(response);

    JsonObject data = json.getJsonObject("data");

    String firstName = data.getString("firstName");
    String lastName = data.getString("lastName");

Upvotes: 0

Related Questions