package com.insthub.ecmobile.protocol;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.external.activeandroid.Model;
import com.external.activeandroid.annotation.Column;
import com.external.activeandroid.annotation.Table;
@Table(name = "categoryResponse")
public class categoryResponse extends Model
{
@Column(name = "status")
public STATUS status;
public ArrayList<CATEGORY> data = new ArrayList<CATEGORY>();
public void fromJson(JSONObject jsonObject) throws JSONException
{
if(null == jsonObject){
return ;
}
JSONArray subItemArray;
STATUS status = new STATUS();
status.fromJson(jsonObject.optJSONObject("status"));
this.status = status;
subItemArray = jsonObject.optJSONArray("data");
if(null != subItemArray)
{
for(int i = 0;i < subItemArray.length();i++)
{
JSONObject subItemObject = subItemArray.getJSONObject(i);
CATEGORY subItem = new CATEGORY();
subItem.fromJson(subItemObject);
this.data.add(subItem);
}
}
return ;
}
public JSONObject toJson() throws JSONException
{
JSONObject localItemObject = new JSONObject();
JSONArray itemJSONArray = new JSONArray();
if(null != status)
{
localItemObject.put("status", status.toJson());
}
for(int i =0; i< data.size(); i++)
{
CATEGORY itemData =data.get(i);
JSONObject itemJSONObject = itemData.toJson();
itemJSONArray.put(itemJSONObject);
}
localItemObject.put("data", itemJSONArray);
return localItemObject;
}
}