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;
    }

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值