首页 > 代码库 > json数组转数组对象

json数组转数组对象

import java.io.IOException;import net.sf.json.JSONArray;import net.sf.json.JSONObject;import com.fasterxml.jackson.core.JsonParseException;import com.fasterxml.jackson.databind.JsonMappingException;import com.fasterxml.jackson.databind.ObjectMapper;public class Test {		public static void main(String[] args) {		//对应实体bean WorkDataInfo 不贴了		 ObjectMapper objectMapper=new ObjectMapper();		 String str =  "[{\"time\":\"2015-01-08 02:06:03\",\"title\":\"zy\",\"status\":-1,\"msgId\":\"f57b624d-7877-4974-94e3-1da77ad93fc0\",\"msgType\":1}]";		// List<WorkDataInfo> list;		try {			WorkDataInfo[]	list =  objectMapper.readValue(str, WorkDataInfo[].class);
              //直接输出对象数组 for (WorkDataInfo workDataInfo : list) { System.out.println(workDataInfo.getTitle()); } } catch (JsonParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JsonMappingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }}

  

json数组转数组对象