private static final ObjectMapper MAPPER = new ObjectMapper();
导入的包
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper;
如:
Map<Long, Object> map = MAPPER.readValue("{"1":"华为(HUAWEI)","2":"华为麦芒5(HUAWEI MLA-AL10)","3":2016.0,"5":160,"6":"其它","7":"Android","8":"骁龙(Snapdragon)","9":"骁龙625(MSM8953)","10":"八核","11":2.0,"14":5.5,"15":"1920*1080(FHD)","16":800.0,"17":1600.0,"18":3340.0}", new TypeReference<Map<Long, Object>>() {});
Map<Long, List<Object>> map = MAPPER.readValue("{"4":["白色","金色","玫瑰金"],"12":["3GB"],"13":["16GB"]}", new TypeReference<Map<Long, List<Object>>>() {});
反序列化的类型根据JSON字符串的格式自行确定