String JSON_STRING_OBJECT = "{\"employee\":{\"name\":\"XYZ\",\"salary\":4000}}";
//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);
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