IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Java知识库 -> Json对象数组转Java对象数组 -> 正文阅读

[Java知识库]Json对象数组转Java对象数组

使用阿里fastjson解析

TestDemo

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;

public class WordCountTest {
     private ArrayList<JsonContent> getPlatformList(String arrStr) {
        ArrayList<JsonContent> jsonContents = new ArrayList<>();
        JSONArray jsonContentList = JSON.parseArray(arrStr);
        for (Object jsonObject : jsonContentList
        ) {
            JsonContent jsonContent = JSONObject.parseObject(jsonObject.toString(), JsonContent.class);
            jsonContents.add(jsonContent);
        }
        return jsonContents;
    }

    @org.junit.Test
    public void wordcount1() throws Exception {
        String jsonStr = "[{\n" +
                "\t\"bg\": \"0\",\n" +
                "\t\"ed\": \"520\",\n" +
                "\t\"onebest\": \"知道\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"1620\",\n" +
                "\t\"ed\": \"2440\",\n" +
                "\t\"onebest\": \"你好。\",\n" +
                "\t\"speaker\": \"1\"\n" +
                "}, {\n" +
                "\t\"bg\": \"2370\",\n" +
                "\t\"ed\": \"3230\",\n" +
                "\t\"onebest\": \"你好。\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"3300\",\n" +
                "\t\"ed\": \"5390\",\n" +
                "\t\"onebest\": \"嗯保修个车辆故障。\",\n" +
                "\t\"speaker\": \"1\"\n" +
                "}, {\n" +
                "\t\"bg\": \"5430\",\n" +
                "\t\"ed\": \"8510\",\n" +
                "\t\"onebest\": \"好的,您这边提供一下您的车牌号是多少多少?\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"9580\",\n" +
                "\t\"ed\": \"12210\",\n" +
                "\t\"onebest\": \"嗯豫AD53206,\",\n" +
                "\t\"speaker\": \"1\"\n" +
                "}, {\n" +
                "\t\"bg\": \"12220\",\n" +
                "\t\"ed\": \"14310\",\n" +
                "\t\"onebest\": \"豫AD53206是吗?\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"15580\",\n" +
                "\t\"ed\": \"17000\",\n" +
                "\t\"onebest\": \"车辆所在的城市\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"17000\",\n" +
                "\t\"ed\": \"18070\",\n" +
                "\t\"onebest\": \"是在哪里的?\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"19640\",\n" +
                "\t\"ed\": \"21910\",\n" +
                "\t\"onebest\": \"河南省许昌市禹州市\",\n" +
                "\t\"speaker\": \"1\"\n" +
                "}, {\n" +
                "\t\"bg\": \"22300\",\n" +
                "\t\"ed\": \"23970\",\n" +
                "\t\"onebest\": \"好的,先生您贵姓?呢\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"25280\",\n" +
                "\t\"ed\": \"26360\",\n" +
                "\t\"onebest\": \"两个姓马。\",\n" +
                "\t\"speaker\": \"1\"\n" +
                "}, {\n" +
                "\t\"bg\": \"26410\",\n" +
                "\t\"ed\": \"29820\",\n" +
                "\t\"onebest\": \"马先生来电尾号是8306能联系您吗?\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"30900\",\n" +
                "\t\"ed\": \"31980\",\n" +
                "\t\"onebest\": \"对,可以。\",\n" +
                "\t\"speaker\": \"1\"\n" +
                "}, {\n" +
                "\t\"bg\": \"31940\",\n" +
                "\t\"ed\": \"33890\",\n" +
                "\t\"onebest\": \"呃车辆是什么问题?呢\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"35240\",\n" +
                "\t\"ed\": \"37210\",\n" +
                "\t\"onebest\": \"嗯就是传动轴坏了。\",\n" +
                "\t\"speaker\": \"1\"\n" +
                "}, {\n" +
                "\t\"bg\": \"37250\",\n" +
                "\t\"ed\": \"39330\",\n" +
                "\t\"onebest\": \"噢是学习中有意向是吗?\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"40450\",\n" +
                "\t\"ed\": \"45120\",\n" +
                "\t\"onebest\": \"对对对,然后我这边找了个修车的师傅,人家看了一下说传统炉坏了。\",\n" +
                "\t\"speaker\": \"1\"\n" +
                "}, {\n" +
                "\t\"bg\": \"45230\",\n" +
                "\t\"ed\": \"48820\",\n" +
                "\t\"onebest\": \"噢好的形式,综上这个这种形式\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"48820\",\n" +
                "\t\"ed\": \"50280\",\n" +
                "\t\"onebest\": \"其实做\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"50520\",\n" +
                "\t\"ed\": \"52540\",\n" +
                "\t\"onebest\": \"有印象。\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"52960\",\n" +
                "\t\"ed\": \"59040\",\n" +
                "\t\"onebest\": \"那个噢嗯查到是桥轴坏了是吗?\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"59810\",\n" +
                "\t\"ed\": \"60510\",\n" +
                "\t\"onebest\": \"对。\",\n" +
                "\t\"speaker\": \"1\"\n" +
                "}, {\n" +
                "\t\"bg\": \"61050\",\n" +
                "\t\"ed\": \"61940\",\n" +
                "\t\"onebest\": \"好好的。\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"62030\",\n" +
                "\t\"ed\": \"63220\",\n" +
                "\t\"onebest\": \"行行行\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"63710\",\n" +
                "\t\"ed\": \"64730\",\n" +
                "\t\"onebest\": \"嗯走\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"65550\",\n" +
                "\t\"ed\": \"66820\",\n" +
                "\t\"onebest\": \"喂\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"66900\",\n" +
                "\t\"ed\": \"68630\",\n" +
                "\t\"onebest\": \"还有其他的车辆问题吗?\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"69640\",\n" +
                "\t\"ed\": \"72020\",\n" +
                "\t\"onebest\": \"嗯目前就发现这一个\",\n" +
                "\t\"speaker\": \"1\"\n" +
                "}, {\n" +
                "\t\"bg\": \"71860\",\n" +
                "\t\"ed\": \"74990\",\n" +
                "\t\"onebest\": \"啊您这边有有准备要去的服务在吗?\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"76840\",\n" +
                "\t\"ed\": \"78640\",\n" +
                "\t\"onebest\": \"嗯\",\n" +
                "\t\"speaker\": \"1\"\n" +
                "}, {\n" +
                "\t\"bg\": \"78640\",\n" +
                "\t\"ed\": \"79840\",\n" +
                "\t\"onebest\": \"呃没有没有。\",\n" +
                "\t\"speaker\": \"1\"\n" +
                "}, {\n" +
                "\t\"bg\": \"80100\",\n" +
                "\t\"ed\": \"85720\",\n" +
                "\t\"onebest\": \"好的那先生,我这边马上为您对接到售后这边让他联系到您具体去哪里维修,您这边注意接听手机。\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"87060\",\n" +
                "\t\"ed\": \"88340\",\n" +
                "\t\"onebest\": \"嗯行好的。\",\n" +
                "\t\"speaker\": \"1\"\n" +
                "}, {\n" +
                "\t\"bg\": \"88090\",\n" +
                "\t\"ed\": \"93240\",\n" +
                "\t\"onebest\": \"好的那先生,我这边就不早了,马上送您报备,感谢您这边的来电,祝您生活愉快,再见。\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"94820\",\n" +
                "\t\"ed\": \"95760\",\n" +
                "\t\"onebest\": \"啊再见。\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}, {\n" +
                "\t\"bg\": \"96810\",\n" +
                "\t\"ed\": \"97930\",\n" +
                "\t\"onebest\": \"嗯\",\n" +
                "\t\"speaker\": \"1\"\n" +
                "}, {\n" +
                "\t\"bg\": \"98450\",\n" +
                "\t\"ed\": \"99310\",\n" +
                "\t\"onebest\": \"嗯\",\n" +
                "\t\"speaker\": \"1\"\n" +
                "}, {\n" +
                "\t\"bg\": \"99230\",\n" +
                "\t\"ed\": \"101250\",\n" +
                "\t\"onebest\": \"这个学校。\",\n" +
                "\t\"speaker\": \"0\"\n" +
                "}]";
        ArrayList<JsonContent> platformList = getPlatformList(jsonStr);
        for (int i = 0; i < platformList.size(); i++) {
            System.out.println(platformList.get(i).getOneBest());
        }
    }
}

JavaBean

public class JsonContent {
    String bg;
    String ed;
    String oneBest;
    String speaker;

    public JsonContent() {
    }

    public String getBg() {
        return bg;
    }

    public void setBg(String bg) {
        this.bg = bg;
    }

    public String getEd() {
        return ed;
    }

    public void setEd(String ed) {
        this.ed = ed;
    }

    public String getOneBest() {
        return oneBest;
    }

    public void setOneBest(String oneBest) {
        this.oneBest = oneBest;
    }

    public String getSpeaker() {
        return speaker;
    }

    public void setSpeaker(String speaker) {
        this.speaker = speaker;
    }

    @Override
    public String toString() {
        return oneBest;
    }

}

  Java知识库 最新文章
计算距离春节还有多长时间
系统开发系列 之WebService(spring框架+ma
springBoot+Cache(自定义有效时间配置)
SpringBoot整合mybatis实现增删改查、分页查
spring教程
SpringBoot+Vue实现美食交流网站的设计与实
虚拟机内存结构以及虚拟机中销毁和新建对象
SpringMVC---原理
小李同学: Java如何按多个字段分组
打印票据--java
上一篇文章      下一篇文章      查看所有文章
加:2022-05-10 11:43:27  更:2022-05-10 11:46:10 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/23 22:51:12-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码