com.alibaba.fastjson.JSON#parseArray(java.lang.String, java.lang.reflect.Type[])想把数据转成List<Map<String, Object>>的类型,为啥Type是一个数组,我理解list都是同一个类型,请教下如何使用
okxuctiv1#
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.TypeReference; import org.junit.Assert; import org.junit.Test; import java.lang.reflect.Type; import java.util.List; import java.util.Map; public class Issue3679 { private static final String list_map_st_obj = "[{\"123\":951753},{\"456\":\"second\"},{\"789\":777},{\"999\":[1,2,3]}]"; @Test public void test1() { List<Object> temp = JSON.parseArray(list_map_st_obj, new Type[]{ new TypeReference<Map<String, Integer>>() { }.getType(), new TypeReference<Map<String, String>>() { }.getType(), new TypeReference<Map<String, Integer>>() { }.getType(), new TypeReference<Map<String, int[]>>() { }.getType(), }); Assert.assertEquals(list_map_st_obj, JSON.toJSONString(temp)); } }
1条答案
按热度按时间okxuctiv1#