java – 不能与杰克逊合作
发布时间:2020-12-14 05:44:38 所属栏目:Java 来源:网络整理
导读:我想知道为什么没有确定的方式与杰克逊合作.我只想解析 JSON字符串: ObjectMapper mapper = new ObjectMapper();Customer[] myObjects = mapper.readValue(file,Customer[].class); 但是我真的很困惑我应该怎么做才能做到这一点.根据这个link,我试图导入map
我想知道为什么没有确定的方式与杰克逊合作.我只想解析
JSON字符串:
ObjectMapper mapper = new ObjectMapper(); Customer[] myObjects = mapper.readValue(file,Customer[].class); 但是我真的很困惑我应该怎么做才能做到这一点.根据这个link,我试图导入mapper-asl.jar.但是我得到这个编译错误: The type org.codehaus.jackson.JsonParser cannot be resolved. It is indirectly referenced from required .class files 然后我尝试导入jackson-core-2.4.2和jackson-databind-2.4.2.所以没有编译错误,但是我得到这个运行时异常(在映射器定义行): java.lang.NoClassDefFoundError: com.fasterxml.jackson.annotation.JsonAutoDetect 引导我,我应该输入什么来与杰克逊合作.谢谢 解决方法
使用这些依赖关系
jackson-databind jackson-annotations jackson-core public class JsonTest { public static void main(String[] args) throws JsonProcessingException { ObjectMapper mapper=new ObjectMapper(); Map<String,String> dt=new Hashtable(); dt.put("1","welcome"); dt.put("2","bye"); String jsonString = mapper.writeValueAsString(dt) System.out.println(jsonString); } } 尝试让我知道,如果它的作品. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |