1

I'm beginner in android (Kotlin).I am getting the Following json from the HTTP Response.

{
    "status": 1,
    "userDetails": [
        {
            "AL_ID": "2",
            "User_Id": "admin",
            "User_Password": "admin",
            "Created_Date": "2020-07-30 11:23:55"
        }
    ],
    "lastlogin": "2020-08-20 12:29:47"
}

I want to get status value from this json. How to get it.

deHaar
  • 14,698
  • 10
  • 35
  • 45
Prashanta Das
  • 11
  • 1
  • 2

1 Answers1

4

You can use the built-in JSONObject and do something as shown below.

val json = JSONObject(jsonString) // String instance holding the above json
val status = json.getInt("status")

Having said that, I'd recommend you to take a look at Gson (for JSON serialization and deserialization) and Retrofit (an HTTP client for Android).

Siddharth Kamaria
  • 1,832
  • 2
  • 12
  • 27