字符串转List<Map>对象,直接上代码:
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import java.util.List;
import java.util.Map;
public class JSONTest {
public static void main(String[] args) {
String str = "[{\"A\": \"喝水\"}, {\"B\": \"喝牛奶\"}, {\"C\": \"虫子\"}, {\"D\": \"吃牛肉\"}, {\"E\": \"吃羊肉\"}]";
List<Map<String, String>> listMap = JSON.parseObject(str, new TypeReference<List<Map<String, String>>>() {
});
System.out.println("listMap = " + listMap);
System.out.println("listMap = " + listMap.get(1).get("B"));
}
}