-2

我有以下需要转换为地图的字符串值,我使用了以下代码

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]
4

1 回答 1

-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());
}
于 2016-06-18T11:44:01.037 回答