import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
@Test
public void JsonObjectToList(){
List<HyPointSet> list = new ArrayList<>();
HyPointSet a = new HyPointSet();
a.setTitle("aaaa");
HyPointSet b = new HyPointSet();
b.setTitle("bbbb");
list.add(a);
list.add(b);
JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(list));//将json字符串转化为JsonArray
JSONObject jsonObject = new JSONObject();
jsonObject.put("array",jsonArray);
//核心方法JsonObjectToList
System.err.println(jsonObject.getString("array"));
List<HyPointSet> result = JSONObject.parseArray(jsonObject.getString("array"),HyPointSet.class);
System.err.println(result);
}
JsonObjectToList
最新推荐文章于 2022-02-12 16:08:53 发布