Hi i am trying to get the json response which has attribute with jsonarray
like (ex: {A:one,B:[{a:one,b:two},{a:two,b:one}]}) i have trying to get
the a:one and b:two values only. But my logcat says error:
- RecyclerView: No adapter attached; skipping layout
- Json parsing error: Value custom_attributes of type java.lang.String cannot be converted to JSONArray
i want to get this values in textview for my product detail view...
My Coding is :
private class GetProductDetails extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
dialog_pro = new ProgressDialog(Product_Detail_Activity.this);
dialog_pro.setMessage("Please wait...");
dialog_pro.setCancelable(false);
dialog_pro.show();
}
@Override
protected Void doInBackground(Void... arg0) {
HttpHandler sh = new HttpHandler();
// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(BaseURL);
//Log.e(TAG, "Response from url: " + jsonStr);
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
name = jsonObj.getString("name");
JSONArray items = new JSONArray("custom_attributes");
for (int i = 0; i < items.length(); i++) {
JSONObject c = items.getJSONObject(i);
String atrr = c.getString("attribute_code");
if(atrr.equalsIgnoreCase("short_description")) {
des = c.getString("value");
}
}
}catch (final JSONException e) {
Log.e(TAG, "Json parsing error: " + e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),
"Json parsing error: " + e.getMessage(),
Toast.LENGTH_LONG)
.show();
// pro_name.setText("Json error:" + e.getMessage());
}
});
}
} else {
//Log.e(TAG, "Couldn't get json from server.");
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),
"Couldn't get json from server. Check LogCat for possible errors!",
Toast.LENGTH_LONG)
.show();
}
});
// AppController.getPermission().addToRequestQueue(jsonObj);
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
/**
* Updating parsed JSON data into ListView
* */
if (dialog_pro.isShowing())
dialog_pro.dismiss();
pro_name.setText(name);
short_desc.setText(des);
}
}