[{"name":"John","id":"a11","age":"30"},{"name":"Mary","id":"a12","age":"25"}] 转成List<Map<String,String>>
时间: 2023-07-03 20:32:10 浏览: 84
可以使用Java中的JSON库来解析这个JSON字符串,然后将解析后的结果转换为List<Map<String,String>>。示例代码如下:
```java
import com.alibaba.fastjson.JSON;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Main {
public static void main(String[] args) {
// 原始JSON字符串
String jsonString = "[{\"name\":\"John\",\"id\":\"a11\",\"age\":\"30\"},{\"name\":\"Mary\",\"id\":\"a12\",\"age\":\"25\"}]";
// 解析JSON字符串
List<Map<String, String>> resultList = new ArrayList<>();
List<Object> list = JSON.parseObject(jsonString, List.class);
for (Object obj : list) {
Map<String, String> map = new HashMap<>();
Map<String, Object> tempMap = (Map<String, Object>) obj;
for (Map.Entry<String, Object> entry : tempMap.entrySet()) {
String key = entry.getKey();
String value = String.valueOf(entry.getValue());
map.put(key, value);
}
resultList.add(map);
}
// 打印结果
System.out.println(resultList);
}
}
```
输出结果为:
```
[{id=a11, name=John, age=30}, {id=a12, name=Mary, age=25}]
```
阅读全文