JSON字符串转化为List<Map>,并根据key取值

利用Alibaba JSON工具将字符串转化为List>,并根据对应的key获取值。

    @Test
    public void test() {
        String str = "[{\"paramName\":\"logtest001\",\"paramType\":\"1\",\"paramOption\":[]},{\"paramName\":\"logtest002\",\"paramType\":\"2\",\"paramOption\":[]},{\"paramName\":\"logtest003\",\"paramType\":\"6\",\"paramOption\":[]},{\"paramName\":\"logtest004\",\"paramType\":\"4\",\"paramOption\":[]}]";
        List<Map<String, String>> listObjectFir = (List<Map<String, String>>) JSONArray.parse(str);
        for (Map<String, String> mapList : listObjectFir) {
            System.out.println("paramName:: " + mapList.get("paramName"));
        }
    }

引用:

import com.alibaba.fastjson.JSONArray;

pom导包:

        <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.51</version>
        </dependency>

你可能感兴趣的:(工作经验总结,json,java,数据结构)