Saturday, 2 May 2020

Json Parsing Android

  String JSON_STRING_OBJECT = "{\"employee\":{\"name\":\"XYZ\",\"salary\":4000}}";

try {
  JsonObject jo = new JsonObject(JSON_STRING_OBJECT);

//Parsing
  JsonObject empObj = jo.getJsonObject("employee");

  String empName = empObj.getString("name");
  String empSal = empObj.getString("salary");

//set text 
  TextView tv = findViewById(R.id.name);
  tv.setText(empName+""+ empSal);

} catch (JSONException e) {
    e.printStackTrace();
}

No comments:

Post a Comment