Reputation: 45
this is my pojo class and i want make method add diary in my diary services class then how to get and set json in this method and any other way to get and set json from setter/getter class.
public class Dairy extends BaseEntity {
public String dairyId;
public String dairyType;
public String productName;
private List<Dairy> dataList;
public List<Dairy> getDataList() {
return dataList;
}
public void setDataList(List<Dairy> dataList) {
this.dataList = dataList;
}
public String getDairyId() {
return dairyId;
}
public void setDairyId(String dairyId) {
this.dairyId = dairyId;
}
public String getDairyType() {
return dairyType;
}
public void setDairyType(String dairyType) {
this.dairyType = dairyType;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
Upvotes: 0
Views: 9581
Reputation: 469
If you hava json like this
product:{
dairyId:"1",
dairyType:"a",
productName:"New Year 2015"
}
You should get like
Dairy d=new Dairy();
You have to use jsonParser class.Then set value on object d.like
JSONObject jsonObject=getJSONObject("product");
d.setDairyId(jsonObject.getString("dairyId");
d.setDairyType(jsonObject.getString("dairyType");
d.setProductName(jsonObject.getString("productName");
To print this value you may use like:
System.out.println("Name is:"+d.getProductName());
I hope this will help to you :)
Upvotes: 1