Jackson解析自定义json到实体类
json文本
{
"status": 0,
"result": {
"final": true,
"hypotheses": [{
"likelihood": 333.86676025390625,
"transcript": "温格你家,",
"word-alignment": [{
"word": "温",
"start": 3.4799999222159386,
"length": 0.20999999530613422
},
{
"word": "格",
"start": 3.689999917522073,
"length": 0.29999999329447746
},
{
"word": "你家",
"start": 4.229999905452132,
"length": 0.3899999912828207
}]
}]
},
"segment-start": 0,
"segment-length": 5.6099998746067286,
"total-length": 5.9658750000000005,
"segment": 0,
"id": "d5e52f52-3d18-4f3e-9379-902183f3ac25"
}
{
"status": 0,
"result": {
"final": true,
"hypotheses": [{
"likelihood": 179.34283447265625,
"transcript": "温格你家小朋友今年上。",
"word-alignment": [{
"word": "温",
"start": 0.6899999845772982,
"length": 0.20999999530613422
},
{
"word": "格",
"start": 0.8999999798834324,
"length": 0.2699999939650297
},
{
"word": "你家",
"start": 1.4399999678134918,
"length": 0.3899999912828207
},
{
"word": "小朋友",
"start": 1.8299999590963125,
"length": 0.6299999859184027
},
{
"word": "今年",
"start": 2.5199999436736107,
"length": 0.41999999061226845
},
{
"word": "上",
"start": 2.969999933615327,
"length": 0.47999998927116394
}]
}]
},
"segment-start": 5.9658750000000005,
"segment-length": 4.0799999088048935,
"total-length": 10.215875,
"segment": 1,
"id": "d5e52f52-3d18-4f3e-9379-902183f3ac25"
}
解析方法:
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException; ObjectMapper objectMapper = new ObjectMapper();
try { ASRRecognizedResponse response = objectMapper.readValue(json, ASRRecognizedResponse.class);
System.out.println(response);
} catch (IOException e) {
e.printStackTrace();
}
相关实体类
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor; @Data
@NoArgsConstructor
public class ASRRecognizedResponse
{
private String status;
private String message; private Result result; @JsonProperty("segment-start")
private String segmentStart; @JsonProperty("segment-length")
private Float segmentLength; @JsonProperty("total-length")
private Float totalLength; private short segment; private String id;
}
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.NoArgsConstructor; @Data
@NoArgsConstructor
@JsonIgnoreProperties("word-alignment")
public class Hypotheses
{
private Float likelihood;
private String transcript;
}
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor; import java.util.List; @Data
@NoArgsConstructor
public class Result{ @JsonProperty("final")
private Boolean finished; private List<Hypotheses> hypotheses;
}
Jackson解析自定义json到实体类的更多相关文章
- fastjson JSON.toJavaObject() 实体类首字母大写属性无法解析问题
fastjson JSON.toJavaObject() 实体类首字母大写属性无法解析问题
- xml转json和实体类的两种方式
本文为博主原创,未经允许不得转载: xml在http通信中具有较高的安全性和传输速度,所以应用比较广泛, 在项目中往往需要对xml,json和实体类进行相互转换,在这里总结一下自己所用到的一些方法: ...
- Visual Studio 2015 将json转换为实体类
最新写的一个接口需要接收json参数,然后序列化为实体类然后再进行后面的逻辑处理.因为json中键值对比较多,逐一去手写实体中的每个属性太麻烦,于是寻思是否有这样的工具可以将json转换为实体类. 经 ...
- 实体类转json 和 json转实体类
1.new JSONObject().toJSONString(rootEntity) JSONObject.toJSONString(specPrices)//specPrices实体类 2. ...
- Dapper解析嵌套的多层实体类
在作项目的时候,我会将一些不涉及查询的字段,形成JSON统一存放在一个字段中,向下面这样的来建实体类, public class WechatModel { public string wechati ...
- JSON反序列化实体类
1.定义实体类 [DataContract] public class CustomerWordOrderViewModel { [DataMember] public string Name; [D ...
- 记录--Gson、json转实体类、类转json
需要导入Gson jar包 最近在做一个java web service项目,需要用到jason,本人对java不是特别精通,于是开始搜索一些java平台的json类库. 发现了google的gson ...
- Gson反序列json到实体类
gson在基准测试过程中各项性能接近于Jackson(具体可以看Benchmark of Java JSON libraries)里面的测试, 本人亲测过,实测结果与他的数据一致,Jackson安全性 ...
- jackson解析处理JSON
package com.ruoyi.common.json; import java.io.File; import java.io.IOException; import java.io.Input ...
随机推荐
- c-free gcc.exe: cannot specify -o with -c or -S and multiple compilations的解决方法
win10上打算使用c-free,因为xp win7时代都用过,写c代码还是比较方便的,尤其是5.0版本,但是在win10上面,c-free 5.0版本没有c-free 4好用,c-free 4启动更 ...
- [Angular 8] Keep original DOM structure with ng-container
ng-container is using for grouping elments together, a bit similar to div. If you want to group some ...
- 当服务全部宕机时候的处理方法,md
 来自为知笔记(Wiz)
- Tensorflow细节-P174-真正的图像预处理
注意这里的读取image_raw_data = tf.gfile.FastGFile("./datasets/cat.jpg", "rb").read(),写入 ...
- 002_基础电路_AD快捷键
AD快捷键设置 陆小果哥哥制作 1. F2----------------------------------------放置走线 a) b) 需设置,点中走线按住 ...
- stos指令
mov ecx,30mov eax,0cccccccchrep stos dword prt es:[edi]stos指令,它的功能是将eax中的数据放入的edi所指的地址中,同时,edi会增加4个字 ...
- docker使(二)—发布node应用镜像和容器
应用在本地是已经ok的了,现在将node应用放进docker容器里面 获取node镜像 docker pull node 编写Dokerfile # 根据node镜像开始创建新的镜像(可以加上:tag ...
- 【概率论】6-3:中心极限定理(The Central Limit Theorem)
title: [概率论]6-3:中心极限定理(The Central Limit Theorem) categories: - Mathematic - Probability keywords: - ...
- 1071 Speech Patterns (25)(25 分)
People often have a preference among synonyms of the same word. For example, some may prefer "t ...
- 《挑战30天C++入门极限》C++的iostream标准库介绍(1)
C++的iostream标准库介绍(1) 我们从一开始就一直在利用C++的输入输出在做着各种练习,输入输出是由iostream库提供的,所以讨论此标准库是有必要的,它与C语言的stdio库不同 ...