java - How to parse this nested JSON array and JSON object View_ID in android -


how "view_id":"v1" , view array.
what create not generating proper response. thing doing wrong?

here response get:

{"success":true,"total":2,"view_id":"v1","view":[{"id":"1","button_id":"acc123_b1","publish_topic":"\/ziniks\/acc123\/sw1","subscribe_topic":"\/ziniks\/acc123\/sw1_status"},{"id":"2","button_id":"acc123_b2","publish_topic":"\/ziniks\/acc123\/sw2","subscribe_topic":"\/ziniks\/acc123\/sw2_status"}]} 

what created response:

jsonobject mainobj = new jsonobject(response); if(mainobj != null){     jsonarray list = mainobj.getjsonarray("view");     if(list != null){         for(int j = 0; j < list.length();j++){             jsonobject innerelem = list.getjsonobject(j);             if(innerelem != null){                 string button_id = innerelem.getstring("button_id");                 toast.maketext(qrcode.this, button_id, toast.length_short).show();             }         }     } } 

    try bellow.   jsonobject mainobj = new jsonobject(response); if(mainobj != null){     string viewid = mainobj.getstring("view_id");  // here view_id.      jsonarray list = mainobj.getjsonarray("view");  // here view array.      if(list != null){ for(int j = 0; j < list.length();j++){ jsonobject innerelem = list.getjsonobject(j); if(innerelem != null){ string button_id = innerelem.getstring("button_id"); toast.maketext(qrcode.this, button_id, toast.length_short).show(); } } } } 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -