码迷,mamicode.com
首页 > 编程语言 > 详细

json数组转数组对象

时间:2015-01-08 19:51:36      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:

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数组转数组对象

标签:

原文地址:http://www.cnblogs.com/huxdiy/p/4211499.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!