问题描述
json={"id":1,"date":1359121059785,filter:["a","b","c"]}如何通过Jackson Json拿到 filter的字符串要类似于JSONObject.fromObject(json).get(filter) 直接可以拿到filter请问怎么做
解决方案
public static void getJson(){String json = "{"id":1,"date":1359121059785,"filter":["a","b","c"]}";ObjectMapper mapper = new ObjectMapper();try {Map<String,Object> map = mapper.readValue(json, Map.class);List<String> stri = (List<String>)map.get("filter");for(String str:stri) System.out.println(str);} catch (JsonParseException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (JsonMappingException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}
时间: 2024-09-24 05:06:47