Java Convert this string to JSONArray [closed]

冷暖自知 提交于 2019-11-29 12:53:55

If you're talking about using the JSON in java library, then since your input string is a JSON object, not a JSON array, you should first load it using JSONObject:

String response=getResponseFromServer();
JSONObject jsonObject = new JSONObject(response);

After that, you can use toJSONArray() to convert a JSONObject to JSONArray given an array of key strings:

String[] names = JSONObject.getNames(jsonObject);
JSONArray jsonArray = jsonObject.toJSONArray(new JSONArray(names));
marlenunez

If you do a search right here on StackOverflow for Java String to JSONArray, you should get this answer: Converting from JSONArray to String then back again

JSONArray jArray;
String s = jArray.toString(); // basically what you have ;)
JSONArray newJArray = new JSONArray(s);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!