json数组如何转换成string类型(超级好用)

先上代码,下面解释
这个jar包地址之后更新的时候再给出来的。
包的地址

JSONObject job = ace.text(a);
//此时job里面的数据格式为
{"logid":2075,"words_result":[{"words":"acb"},{"words":"and)已知函数f(x)"},{"words":"def"},{"words":"hij"},{"words":"klm"}],"wordsnum":5}


String objects = job.get("words_result").toString();
//获取到json数据中数组的那一部分

JSONArray jsonarray = new JSONArray(objects);
//将提取出来数组的那一部分封装到json数组对象中。

List lists = new ArrayList<>();
for (int i = 0; i < jsonarray.length(); i++) {          lists.add(i,jsonarray.getJSONObject(i).get("words"));

        }
//通过循环,将json数组中key为words的数据添加到list集合中

String str = lists.toString();
//最后将list集合中的数据赋值给字符str中,到这里转化完成


上面我是先获取了含有json数组的json数据,如果你有现成的json数组的话,那就省了前面转化的一些步骤了。


JSONObject在线api:http://json-lib.sourceforge.net/apidocs/jdk15/index.html

你可能感兴趣的:(网站开发,数据,json,string)