我有以下需要转换为map的字符串值,我使用了以下代码
String parameters='[{"key":"login","value":"admin"},{"key":"Createddate","value":"cairo"}]';
ObjectMapper mapper = new ObjectMapper();
Map<String, String> map ;
map = mapper.readValue(parameters, new TypeReference<Map<String, String>>(){});
System.out.println(map);
我收到以下错误
com.fasterxml.jackson.databind.JsonMappingException: Can not
deserialize instance of java.util.LinkedHashMap out of START_ARRAY token
at [Source: [{"key":"login","value":"admin"},
{"key":"Createddate","value":"cairo"}]; line: 1, column: 1]
答案 0 :(得分:-1)
String param="[{\"key\":\"login\",\"value\":\"admin\"},{\"key\":\"Createddate\",\"value\":\"cairo\"}]";
ObjectMapper mapper = new ObjectMapper();
List maps = mapper.readValue(param, List.class);
for (int i=0 ; i<maps.size() ; i++){
Log.d("MAP", maps.get(i).toString());
}