Response of my json is given below,and I am trying to parse data,but when I parse user_photo_id,it gives JSONException:No values for user_photo_id,can any one tell me?
{
"user_login_id": "2650",
"user_total_photo": "3",
"max_upload_photo": "3",
"image_list": [
{
"user_photo_id": 334,
"status": "Approved",
"photo": ""
},
{
"user_photo_id": 394,
"status": "Approved",
"photo": ""
},
{
"user_photo_id": 398,
"status": "Admin Approve Remaining",
"photo": ""
}
]
}
my java code:
class LoadImages extends AsyncTask<String, String, ArrayList<HashMap<String,String>>> {
String photoid;
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(getActivity());
pDialog.setMessage("Loading...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
protected ArrayList<HashMap<String,String>> doInBackground(String... args) {
ServiceHandler sh = new ServiceHandler();
// Making a request to url and getting response
ArrayList<HashMap<String,String>> data = new ArrayList<HashMap<String, String>>();
String jsonStr = sh.makeServiceCall(IMAGE_URL, ServiceHandler.GET);
Log.d("Response: ", "> " + jsonStr);
try {
jsonObj = new JSONObject(jsonStr);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(IMAGE_USERLOGIN_ID, jsonObj.getString(IMAGE_USERLOGIN_ID));
map.put(IMAGE_TOTAL_PHOTO,jsonObj.getString(IMAGE_TOTAL_PHOTO));
map.put(IMAGE_MAX_UPLOAD, jsonObj.getString(IMAGE_MAX_UPLOAD));
/*map.put(IMAGE_USER_PHOTOID, jsonObj.getString(IMAGE_USER_PHOTOID));
map.put(IMAGE_STATUS, jsonObj.getString(IMAGE_STATUS));
map.put(IMAGE_PHOTO, jsonObj.getString(IMAGE_PHOTO));
*/
image_list = (JSONArray) jsonObj.get(IMAGE_LISTING);
for(int i=0;i< image_list.length();i++)
{
photoid += image_list.get(i);
Log.d("mylog", "initial marital = " + photoid);
}
getActivity().runOnUiThread(new Runnable()
{
@Override
public void run()
{
Intent intent=new Intent(getActivity(),PhotoView.class);
intent.putExtra("id", id);
intent.putExtra("totals", totalphota);
intent.putExtra("maxs", maximumphota);
startActivity(intent);
}
});
/* image_list = (JSONArray) jsonObj.get("user_photo_id");
image_list=(JSONArray) jsonObj.get(IMAGE_STATUS);
image_list=(JSONArray)jsonObj.get(IMAGE_PHOTO);
for(int i=0;i< image_list.length();i++)
{
String photoid=
}*/
} catch (JSONException e) {
e.printStackTrace();
}
return data;
}
protected void onPostExecute(ArrayList<HashMap<String,String>> result) {
super.onPostExecute(result);
// dismiss the dialog after getting all albums
if (pDialog.isShowing())
pDialog.dismiss();
// updating UI from Background Thread
/*Intent mIntent = new Intent(getActivity(),Filter.class);
Bundle extras = mIntent.getExtras();
try {
extras.putString("radiostatus", jsonObj.getString(FILTER_ALLOW));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} */
}
}