java - JSONObject getString(String.valueof(variable integer)) not working -


i have searched lot answer or explanation why "jsonobject.getstring()" not working. first response php server

{"3":["s1","2013","final"],"2":["s0","2010","mid"],"1":["s6","2015","final"]} 

this code:

        ccnerequest.add(new basicnamevaluepair("semester", "s"));         ccnejsonstring = ccneexams.getjsonfromurl(ccneurl, ccnerequest);         if (ccnejsonstring != null) {             try {                 jsonobject jobj = new jsonobject(ccnejsonstring);              (int = 0; < jobj.length(); i++) {                      jsonarray jsonarray = new jsonarray(                             jobj.getstring(values[i]));               } 

this code working fine me while values[] array implemented this:

public string[] values = { "1", "2", "3", "4", "5", "6", "7", "8", "9",         "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",         "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31",         "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42",         "43", "44", "45", "46", "47", "48", "49", "50" }; 

now in future might have more 1000 jsonobjects, don't want implement array values[] since want wright nice code , efficient, tried replace array values[i] exact number of jsonobjects this:

ccnerequest.add(new basicnamevaluepair("semester", "s"));         ccnejsonstring = ccneexams.getjsonfromurl(ccneurl, ccnerequest);         if (ccnejsonstring != null) {             try {                 jsonobject jobj = new jsonobject(ccnejsonstring);              (int = 0; < jobj.length(); i++) {                      jsonarray jsonarray = new jsonarray(                             jobj.getstring(string.valueof(i));               } 

in way don't have implement values[] in code unfortunately not working, throwing exception on

jsonarray jsonarray = new jsonarray(                             jobj.getstring(string.valueof(i)); 

so question is, why making exception error while giving converted variable string in jsonobject.getstring() , way rid of array of strings values[] , use method gives me same results without implementing static??

in first loop iteration, i 0, there no key 0 in jsonobject. results in jsonexception.

you should start loop 1.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -