Following is the json data which i am getting from an api
{
"list": {
"items": [
"About Us",
"Services",
"Working With",
"Officehours",
"Useful Links",
"Terms & Conditions",
"Go to Website"
]
},
"data":
{
"about us": { "description": " Aaaaaaaa" },
"services": { "description": " Baaaaaaa." },
"working with": { "description": "Caaaaaa" },
"officehours": { "title": "Office Hours:","timing": "09:00am - 06:00pm"},
"useful links": { "description": [
{
"name": "One",
"link": "http://www.google.com/"
},
{
"name": "Two",
"link": "http://www.yahoo.com"
}]},
"terms & conditions": { "description": "Daaaaaaaaa" },
"go to website": { "link": "http: //www.amazon.com/" },
}
}
In the above json data the “list” values in the json array are to be show in a listview. I have added them in an array list and shown in a list view too.
Now when the user clicks on the list view the data corresponding to them are shown in the next activity. For example if the user clicks on the About US text of listview then i how to show the description Aaaaaaa in the next activity.
Like this for each item in list view i have to open different activity.
If the inner tag is description i have to open activity1
If the inner tag is title i have to open activity2
If the inner tag is link i have to open activity3
If the inner tag is description is to be an JSON array type, have to open activity4
I am not supposed to hot code the tags such as "about us", "services","working with","officehours","useful links","terms & conditions", "go to website" within the code.
In my OnItemClickListener i am doing the following
try
{
JSONObject locarray = new JSONObject(Appconstant.dataObj.get(0).toString());
String txt_data = locarray.getJSONObject(about.get(arg2).toLowerCase()).getString("description");
}
catch(Exception e)
{
Log.e("Exception @ json 1",""+e);
}
in some cases i am getting an exception saying that there is no JSOn value of “description”
how to get this to be done, pls help me
one way of doing it is by
not sure if this might help 🙂 if there is a case were the description is blank use