codeHunter codeHunter - 2 years ago 114
Android Question

Any shortcut or plugin to generate constructor with parameter JSONObject as following code

class Person {
String name;
String age;

public Person(JSONObject obj) throws exception{
this.name = obj.getString("name");
this.age = obj.getString("age");
}
}


Those are few attributes but I have a huge list of other attributes. I know shortcut about how to create constructer, getter, setter. But I don't know a shortcut to create the above code automatically.

Answer Source

Use google's gson library gson

Like this

Gson gson = new Gson();
Person person = gson.fromJson(jsonInString, Person.class);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download