当前位置 : 主页 > 编程语言 > c++ >

Jackson的读取和生成

来源:互联网 收集:自由互联 发布时间:2021-06-30
Jackson.java // JSON转换成对象ObjectMapper mapper = new ObjectMapper();AccessToken token = mapper.readValue(result, AccessToken.class);//不创建对象,直接读取:Map map = mapper.readValue(result, Map.class)//对象转JSONObjec
Jackson.java
// JSON转换成对象
ObjectMapper mapper = new ObjectMapper();
AccessToken token = mapper.readValue(result, AccessToken.class);

//不创建对象,直接读取:
Map map = mapper.readValue(result, Map.class)


//对象转JSON
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeAsString(new AccessToken())
build.gradle
// 导入依赖
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.1'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.1'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.9.1'
网友评论