json転送リスト

1949 ワード


import java.util.Arrays;
import java.util.List;

import com.alibaba.fastjson.JSONArray;

public class JsonListUtil {

    /**
     * json   List
     */
    public static  List jsonToList(String jsonString, Class clazz) {
        @SuppressWarnings("unchecked")
        List ts = (List) JSONArray.parseArray(jsonString, clazz);
        return ts;
    }
    
	public static void main(String args[]) {
		String jsonString = "[{\r
" + " \"time\": 1543507200000,\r
" + " \"value\": \" \"\r
" + "}, {\r
" + " \"time\": 1543852800000,\r
" + " \"value\": \" \"\r
" + "}, {\r
" + " \"time\": 1544544000000,\r
" + " \"value\": \" \"\r
" + "}, {\r
" + " \"time\": 1543766400000,\r
" + " \"value\": \" \"\r
" + "}, {\r
" + " \"time\": 1543766400000,\r
" + " \"value\": \" \"\r
" + "}, {\r
" + " \"time\": 1543766400000,\r
" + " \"value\": \" \"\r
" + "}, {\r
" + " \"time\": 1543766400000,\r
" + " \"value\": \" \"\r
" + "}, {\r
" + " \"time\": 1543766400000,\r
" + " \"value\": \" \"\r
" + "}]"; List list = jsonToList(jsonString, HelpClassString.class); for (int i = 0; i < list.size(); i++) { HelpClassString helpClassString = list.get(i); System.err.println(helpClassString.getValue()); } } }