{
"Catagories": [
{
"cat_id": "01",
"name": "Business",
"logo": "catagoryLogo1",
"sub_catagories": [
{
"subcat_id": "11",
"name": "Business11",
"logo": "logo11",
"lat": "21.7600",
"lon": "72.1500",
"detail": {
"street": "stres-1",
"city": "Amd",
"state": "Guj",
"zipcode": "364005",
"description": "Restorant Description",
"services": "Rest services",
"working_hour": "08",
"contact_no": "0792431233",
"e-mail": "user@pidex.ca",
"website": "www.pidex.com",
"image": [
"img0",
"img1",
"img2",
"img3",
"img4",
"img5",
"img6",
"img7"
]
}
},
{
"subcat_id": "12",
"name": "Business12",
"logo": "logo12",
"lat": "21.7600",
"lon": "72.1500",
"detail": {
"street": "stres-1",
"city": "Amd",
"state": "Guj",
"zipcode": "364005",
"description": "Restorant Description",
"services": "Rest services",
"working_hour": "08",
"contact_no": "0792431233",
"e-mail": "user@pidex.ca",
"website": "www.pidex.com",
"image": [
"img0",
"img1",
"img2",
"img3",
"img4",
"img5",
"img6",
"img7"
]
}
},
{
"subcat_id": "13",
"name": "Business13",
"logo": "logo13",
"lat": "21.7600",
"lon": "72.1500",
"detail": {
"street": "stres-1",
"city": "Amd",
"state": "Guj",
"zipcode": "364005",
"description": "Restorant Description",
"services": "Rest services",
"working_hour": "08",
"contact_no": "0792431233",
"e-mail": "user@pidex.ca",
"website": "www.pidex.com",
"image": [
"img0",
"img1",
"img2",
"img3",
"img4",
"img5",
"img6",
"img7"
]
}
},
]
},
{
"cat_id": "02",
"name": "Restorant",
"logo": "catagoryLogo2",
"sub_catagories": [
{
"subcat_id": "21",
"name": "Restorant21",
"logo": "logo21",
"lat": "21.7600",
"lon": "72.1500",
"detail": {
"street": "stres-1",
"city": "Amd",
"state": "Guj",
"zipcode": "364005",
"description": "Restorant Description",
"services": "Rest services",
"working_hour": "08",
"contact_no": "0792431233",
"e-mail": "user@pidex.ca",
"website": "www.pidex.com",
"image": [
"img0",
"img1",
"img2",
"img3",
"img4",
"img5",
"img6",
"img7"
]
}
},
{
"subcat_id": "22",
"name": "Restorant22",
"logo": "logo22",
"lat": "21.7600",
"lon": "72.1500",
"detail": {
"street": "stres-1",
"city": "Amd",
"state": "Guj",
"zipcode": "364005",
"description": "Restorant Description",
"services": "Rest services",
"working_hour": "08",
"contact_no": "0792431233",
"e-mail": "user@pidex.ca",
"website": "www.pidex.com",
"image": [
"img0",
"img1",
"img2",
"img3",
"img4",
"img5",
"img6",
"img7"
]
}
},
{
"subcat_id": "23",
"name": "Restorant23",
"logo": "logo23",
"lat": "21.7600",
"lon": "72.1500",
"detail": {
"street": "stres-1",
"city": "Amd",
"state": "Guj",
"zipcode": "364005",
"description": "Restorant Description",
"services": "Rest services",
"working_hour": "08",
"contact_no": "0792431233",
"e-mail": "user@pidex.ca",
"website": "www.pidex.com",
"image": [
"img0",
"img1",
"img2",
"img3",
"img4",
"img5",
"img6",
"img7"
]
}
},
]
},
{
"cat_id": "03",
"name": "Shop",
"logo": "catagoryLogo3",
"lon": "72.1500",
"sub_catagories": [
{
"subcat_id": "31",
"name": "Shop31",
"logo": "logo31",
"lat": "21.7600",
"lon": "72.1500",
"detail": {
"street": "stres-1",
"city": "Amd",
"state": "Guj",
"zipcode": "364005",
"description": "Restorant Description",
"services": "Rest services",
"working_hour": "08",
"contact_no": "0792431233",
"e-mail": "user@pidex.ca",
"website": "www.pidex.com",
"image": [
"img0",
"img1",
"img2",
"img3",
"img4",
"img5",
"img6",
"img7"
]
}
},
{
"subcat_id": "32",
"name": "Shop32",
"logo": "logo32",
"lat": "21.7600",
"lon": "72.1500",
"detail": {
"street": "stres-1",
"city": "Amd",
"state": "Guj",
"zipcode": "364005",
"description": "Restorant Description",
"services": "Rest services",
"working_hour": "08",
"contact_no": "0792431233",
"e-mail": "user@pidex.ca",
"website": "www.pidex.com",
"image": [
"img0",
"img1",
"img2",
"img3",
"img4",
"img5",
"img6",
"img7"
]
}
},
{
"subcat_id": "33",
"name": "Shop33",
"logo": "logo33",
"lat": "21.7600",
"lon": "72.1500",
"detail": {
"street": "stres-1",
"city": "Amd",
"state": "Guj",
"zipcode": "364005",
"description": "Restorant Description",
"services": "Rest services",
"working_hour": "08",
"contact_no": "0792431233",
"e-mail": "user@pidex.ca",
"website": "www.pidex.com",
"image": [
"img0",
"img1",
"img2",
"img3",
"img4",
"img5",
"img6",
"img7"
]
}
},
]
}
]
}
这里我有一个 JSON 字符串。如何解析并将其存储在这个特定的类对象中?
public static void getDomainData() {
try {
JSONObject jsonobj = new JSONObject(Result);
BusinessAllDataClass AllData = new BusinessAllDataClass();
if (jsonobj.has(Constants.Cat)) {
List<CategoryDataClass> Cat_list = new ArrayList<CategoryDataClass>();
CatData = jsonobj.getJSONArray(Constants.Cat);
for (int i = 0; i < CatData.length(); i++) {
CategoryDataClass Cat = new CategoryDataClass();
JSONObject objCat = CatData.getJSONObject(i);
if (objCat.has(Constants.Cat_ID)) {
Cat.setCatId(objCat.getString(Constants.Cat_ID));
}
if (objCat.has(Constants.Cat_NAME)) {
Cat.setCatName(objCat.getString(Constants.Cat_NAME));
}
if (objCat.has(Constants.Cat_Logo)) {
Cat.setCatLogo(objCat.getString(Constants.Cat_Logo));
}
if (objCat.has(Constants.Sub_Cat)) {
SubCat_list = new ArrayList<SubCategoryDataClass>();
SubCatData = objCat.getJSONArray(Constants.Sub_Cat);
for (int j = 0; j < 3; j++) {
SubCategoryDataClass SubCat = new SubCategoryDataClass();
JSONObject objSubCat = SubCatData.getJSONObject(j);
if (objSubCat.has(Constants.Sub_CatID)) {
SubCat.setSubCatId(objSubCat
.getString(Constants.Sub_CatID));
}
if (objSubCat.has(Constants.Sub_CatNAME)) {
SubCat.setSubCatName(objSubCat
.getString(Constants.Sub_CatNAME));
}
if (objSubCat.has(Constants.Sub_CatLogo)) {
SubCat.setSubCatLogo(objSubCat
.getString(Constants.Sub_CatLogo));
}
if (objSubCat.has(Constants.Longitude)) {
SubCat.setLongitude(objSubCat
.getString(Constants.Longitude));
}
if (objSubCat.has(Constants.Latitudde)) {
SubCat.setLatitiude(objSubCat
.getString(Constants.Latitudde));
}
if (objSubCat.has(Constants.Description)) {
List<SubCategorDescriptionDataClass> SubCatDescription_list = new ArrayList<SubCategorDescriptionDataClass>();
JSONObject DescObj = objSubCat
.getJSONObject(Constants.Description);
SubCategorDescriptionDataClass SubCatDesc = new SubCategorDescriptionDataClass();
if (DescObj.has(Constants.Street)) {
SubCatDesc.setStreet(DescObj
.getString(Constants.Street));
}
if (DescObj.has(Constants.City)) {
SubCatDesc.setCity(DescObj
.getString(Constants.City));
}
if (DescObj.has(Constants.State)) {
SubCatDesc.setState(DescObj
.getString(Constants.State));
}
if (DescObj.has(Constants.Zipcode)) {
SubCatDesc.setzipcode(DescObj
.getString(Constants.Zipcode));
}
if (DescObj.has(Constants.DataDescription)) {
SubCatDesc
.setDesc(DescObj
.getString(Constants.DataDescription));
}
if (DescObj.has(Constants.Services)) {
SubCatDesc.setServices(DescObj
.getString(Constants.Services));
}
if (DescObj.has(Constants.WorkingHour)) {
SubCatDesc.setWorkingHour(DescObj
.getString(Constants.WorkingHour));
}
if (DescObj.has(Constants.Contact_No)) {
SubCatDesc.setContactNo(DescObj
.getString(Constants.Contact_No));
}
if (DescObj.has(Constants.Usre_Email)) {
SubCatDesc.setUsreEmail(DescObj
.getString(Constants.Usre_Email));
}
if (DescObj.has(Constants.Website)) {
SubCatDesc.setWebsite(DescObj
.getString(Constants.Website));
}
if (DescObj.has(Constants.Image)) {
DescImage = DescObj
.getJSONArray(Constants.Image);
Log.e("JsonArray",
String.valueOf(DescImage.length()));
for (int k = 0; k < DescImage.length(); k++) {
SubCatDesc.ImageData.add(DescImage
.getString(k));
}
SubCatDescription_list.add(SubCatDesc);
SubCat.setSubCatDescList(SubCatDescription_list);
}
SubCat_list.add(SubCat);
Cat.setSubCatList(SubCat_list);
}
}
}
Cat_list.add(Cat);
}
AllData.setCatList(Cat_list);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}