android - Convert JSONArray to String[] -


JSONArray due to some problems in the format, it will be out this way:

  string [] title = {"commentator's name 1", "commentator's name 2", "commentator's name 3"};   

This is my JSON:

  "commentator": [ "commentator's name 1", "commentator's name 2", "commentator's name 3 "]   

and this is my code:

  // getting JSON string URL JSONObject json = userFunction.getAudios (); & Lt; String & gt; List = New Arrestist & lt; String & gt; (); Try {Commenter = json.getJSONArray (TAG_COMENTATOR); Log D. ("Commentator", commentator.stosting ()); //sistmkautkprintelan("******************************) if (commentator! = NULL) to { (Int i = 0; i & lt; Kmentetrklambi (); i ++) {log d. ( "for" loop, "value" + commentator .getString (i)); list.add (commentator. GetString (i));}}} Grab (Jasonnexpress E) {// Tudo auto-generated catch block e.printStackTrace ();} string [] title = list.toArray (new string [list.size ()]);   

but im gaining an index of direct error with this code, im not feel formatted its well, a Also consider ?? Thanks in advance

try it

  JSONArray jsonArr = New JSONArray (resultString); JSONArray for jsonArr2 = jsonArr.getJSONArray (0); for (int i = 0; i & lt; jsonArr2.length (); i ++) {list.add (jsonArr2.getString (i). );}   

is the result string json string. It all rewrites the Jason array and adds it to your array of string < / div>

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -