如何把json字符串转化为list
List list = new ArrayList()
list.add("测试1")
list.add("测试2")
list.add("测试3")
JSONArray jsonArray = JSONArray.fromObject(list)
System.out.println(jsonArray.toString())
这边要导包需要用到json-lib.jar, net.sf.json.JSONArray
如何将json类型的字符串转换成list
String list = request.getParameter("json")
JSONArray data = JSONArray.fromObject(list)
for(int i=0iJSONObject jobj = (JSONObject) data.get(i) String name = jobj.get("name") }
怎么把json string数据转换成list集合
将json字符串转成Java的Array数组 private String json = "{"address":"chian","birthday":{"birthday":"2010-11-22"}," ""email":"email@123.com","id":22,"name":"tom"}" @Test public void readJSON2Array()
Json格式的数据怎么转换成List
JSONObject.toBean
String list = request.getParameter("json")
JSONArray data = JSONArray.fromObject(list)
for(int i=0i JSONObject jobj = (JSONObject) data.get(i)
String name = jobj.get("name")
}
以上代码就是从json数组装换的。
JSON字符串怎么转List和map集合
package jsonToMap
import java.util.List
import java.util.Map
import java.util.Map.Entry
import net.sf.json.JSONArray
import net.sf.json.JSONObject
/**
 * 说明 json字符串 转成 Map/List
 */
public class JsonToMap {
public static void main(String[] args) {
//JSONArray
String jsonArrayData="[{"a1":"12","b1":"112","c1":"132","d1":"134"},{"a2":"12","b2":"112","c2":"132","d2":"134"},{"a3":"12","b3":"112","c3":"132","d3":"134"}]"
JSONArray jsonArray = JSONArray.fromObject(jsonArrayData)
List