JAVA 数组格式的json字符串转换成List

一.

import org.codehaus.jackson.type.TypeReference;
import org.codehaus.jackson.map.ObjectMapper; ObjectMapper mapper = new ObjectMapper();
List<Object> list = mapper.readValue(message,
new TypeReference<List<Object>>() {});

二.

1.maven

    <dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>

1.实现

import net.sf.json.JSONArray;
import net.sf.json.JSONObject; Object[] obj = getJosnToArray(message, TmTransportSysncVehicleInfo.class);
public static <T> Object[] getJosnToArray(String jsonString, Class<T> classz) {
// net.sf.jso
JSONArray array = JSONArray.fromObject(jsonString);
Object[] obj = new Object[array.size()];
for (int i = ; i < array.size(); i++) {
JSONObject jsonObject = array.getJSONObject(i);
obj[i] = JSONObject.toBean(jsonObject, classz);
}
return obj;
}
上一篇:JS--变量及深浅拷贝


下一篇:Java将CST的时间字符串转换成需要的日期格式字符串