在不确定的情况循环嵌套的JSON怎么解析? 5C

结构大概是这样的
下面是模拟数据 要用"chian" 字段写一个
{
"datas" : [ {
"payAmount" : 0,
"area" : "滁州市",
"userId" : "3638b61f7ef74d95ad6c14d8bc0644ff",
"chainCount" : 3,
"seq" : 1,
"userName" : "还是收到",
"receiveAmount" : 7.00,
"chian" : [ {
"amount" : 7.00,
"node" : 1,
"area" : "",
"debtorName" : "还是",
"accountId" : "AC20180810000616",
"debtorId" : "43ded7a2d9b647d3bd1d8a5f7125dab4",
"creditorId" : "3638b61f7ef74d95ad6c14d8bc0644ff",
"children" : [ {
"amount" : 6.00,
"node" : 2,
"area" : "",
"debtorName" : "士大夫",
"accountId" : "AC20180907000652",
"debtorId" : "265581f4b83540a09cd8fba8797e7065",
"creditorId" : "43ded7a2d9b647d3bd1d8a5f7125dab4",
"children" : [ ],
"creditorName" : "还是"
}, {
"amount" : 2.00,
"node" : 2,
"area" : "",
"debtorName" : "海阔天空",
"accountId" : "AC20180912000657",
"debtorId" : "a41dac80eaf940d58bcda3fe42faaaa3",
"creditorId" : "43ded7a2d9b647d3bd1d8a5f7125dab4",
"children" : [ {
"amount" : 4.00,
"node" : 3,
"area" : "",
"debtorName" : "士大夫",
"accountId" : "AC20180907000651",
"debtorId" : "265581f4b83540a09cd8fba8797e7065",
"creditorId" : "a41dac80eaf940d58bcda3fe42faaaa3",
"children" : [ ],
"creditorName" : "海阔天空"
} ],
"creditorName" : "还是"
}, {
"amount" : 90000000.00,
"node" : 2,
"area" : "",
"debtorName" : "士大夫",
"accountId" : "AC20180824000639",
"debtorId" : "265581f4b83540a09cd8fba8797e7065",
"creditorId" : "43ded7a2d9b647d3bd1d8a5f7125dab4",
"children" : [ ],
"creditorName" : "还是"
} ],
"creditorName" : "还是收到"
} ],
"rongziAll" : 90000008.00
}, {
"financeAmount" : 0,
"payAmount" : 0,
"area" : "抚顺市",
"userId" : "3a33493363594bdfaa304586ab62668c",
"chainCount" : 0,
"seq" : 2,
"userName" : "A",
"receiveAmount" : 0,
"chian" : "",
"rongziAll" : 0
}, {
"payAmount" : 0,
"area" : "佳木斯市",
"userId" : "c92fce2d51154fc597421c0c2d4f9171",
"chainCount" : 1,
"seq" : 3,
"userName" : "阿甘船运有限公司",
"receiveAmount" : 1500000.00,
"chian" : [ {
"amount" : 1500000.00,
"node" : 1,
"area" : "",
"debtorName" : "澳洲太和矿业有限公司",
"accountId" : "AC20180412000452",
"debtorId" : "1acc2644a97541e5a9291120e379f416",
"creditorId" : "c92fce2d51154fc597421c0c2d4f9171",
"children" : [ ],
"creditorName" : "阿甘船运有限公司"
} ],
"rongziAll" : 1500000.00
}, {
"financeAmount" : 0,
"payAmount" : 0,
"area" : "南昌市",
"userId" : "1260d446161c4d7c8220e5addccc30ed",
"chainCount" : 0,
"seq" : 4,
"userName" : "个人附件阿萨德",
"receiveAmount" : 0,
"chian" : "",
"rongziAll" : 0
}, {
"financeAmount" : 0,
"payAmount" : 0,
"area" : "伊犁哈萨克自治州",
"userId" : "3fdc805022814024872428a5cefc9793",
"chainCount" : 0,
"seq" : 5,
"userName" : "贺声耀",
"receiveAmount" : 0,
"chian" : "",
"rongziAll" : 0
}, {
"payAmount" : 7.00,
"area" : "滁州市",
"userId" : "43ded7a2d9b647d3bd1d8a5f7125dab4",
"chainCount" : 3,
"seq" : 6,
"userName" : "还是",
"receiveAmount" : 90000008.00,
"chian" : [ {
"amount" : 6.00,
"node" : 1,
"area" : "",
"debtorName" : "士大夫",
"accountId" : "AC20180907000652",
"debtorId" : "265581f4b83540a09cd8fba8797e7065",
"creditorId" : "43ded7a2d9b647d3bd1d8a5f7125dab4",
"children" : [ ],
"creditorName" : "还是"
}, {
"amount" : 2.00,
"node" : 1,
"area" : "",
"debtorName" : "海阔天空",
"accountId" : "AC20180912000657",
"debtorId" : "a41dac80eaf940d58bcda3fe42faaaa3",
"creditorId" : "43ded7a2d9b647d3bd1d8a5f7125dab4",
"children" : [ {
"amount" : 4.00,
"node" : 2,
"area" : "",
"debtorName" : "士大夫",
"accountId" : "AC20180907000651",
"debtorId" : "265581f4b83540a09cd8fba8797e7065",
"creditorId" : "a41dac80eaf940d58bcda3fe42faaaa3",
"children" : [ ],
"creditorName" : "海阔天空"
} ],
"creditorName" : "还是"
}, {
"amount" : 90000000.00,
"node" : 1,
"area" : "",
"debtorName" : "士大夫",
"accountId" : "AC20180824000639",
"debtorId" : "265581f4b83540a09cd8fba8797e7065",
"creditorId" : "43ded7a2d9b647d3bd1d8a5f7125dab4",
"children" : [ ],
"creditorName" : "还是"
} ],
"rongziAll" : 90000008.00
}, {
"financeAmount" : 0,
"payAmount" : 1500000.00,
"area" : "长春市",
"userId" : "1acc2644a97541e5a9291120e379f416",
"chainCount" : 0,
"seq" : 7,
"userName" : "澳洲太和矿业有限公司",
"receiveAmount" : 0,
"chian" : "",
"rongziAll" : 0
}, {
"financeAmount" : 0,
"payAmount" : 0,
"area" : "怀化市",
"userId" : "7869179be7b74951994de20448970fe3",
"chainCount" : 0,
"seq" : 8,
"userName" : "Shhshs",
"receiveAmount" : 0,
"chian" : "",
"rongziAll" : 0
}, {
"payAmount" : 2.00,
"area" : "贵阳市",
"userId" : "a41dac80eaf940d58bcda3fe42faaaa3",
"chainCount" : 1,
"seq" : 9,
"userName" : "海阔天空",
"receiveAmount" : 4.00,
"chian" : [ {
"amount" : 4.00,
"node" : 1,
"area" : "",
"debtorName" : "士大夫",
"accountId" : "AC20180907000651",
"debtorId" : "265581f4b83540a09cd8fba8797e7065",
"creditorId" : "a41dac80eaf940d58bcda3fe42faaaa3",
"children" : [ ],
"creditorName" : "海阔天空"
} ],
"rongziAll" : 4.00
}, {
"financeAmount" : 0,
"payAmount" : 90000010.00,
"area" : "澳门",
"userId" : "265581f4b83540a09cd8fba8797e7065",
"chainCount" : 0,
"seq" : 10,
"userName" : "士大夫",
"receiveAmount" : 0,
"chian" : "",
"rongziAll" : 0
} ],
"result" : "success",
"count" : 10,
"page" : "1",
"msg" : "0"
}

7个回答

可以用递归,也可以不用。递归简单,就不说了。
不用递归伪代码如下:

当前层次 = 1;
do
{
n = 遍历层次为1的,添加到列表,返回数量
当前层次++;
} while (n > 0);

像这种情况,一个bean是解决不了的children 是个循环体,不确定是否存在,所以用的时候判断一下是否是null,不为null再判断下层如此就ok了

手动解析,只要是解析数组之前先判断size是不是为0就可以了,用手动解析应该是比较快的方法

我真是闲的无聊

代码

package com.vzoom.ath.wsc.json;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.List;

import com.alibaba.fastjson.JSON;

public class Main {

    public static void main(String[] args) throws Exception {
        String filePath = "F://my-json.txt";
        BufferedReader reader = new BufferedReader(new FileReader(filePath));
        String temp = null;
        StringBuffer sbuffer = new StringBuffer();
        while ((temp = reader.readLine()) != null) {
            sbuffer.append(temp);
        }

        String jsonContent = sbuffer.toString();
        System.out.println(jsonContent);
        MyJson myJson = JSON.parseObject(jsonContent, MyJson.class);
        System.out.println(JSON.toJSONString(myJson));
        reader.close();
    }
}

class Children {

    private double amount;
    private int node;
    private String area;
    private String debtorName;
    private String accountId;
    private String debtorId;
    private String creditorId;
    private String creditorName;
    private List<Children> children;

    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    public int getNode() {
        return node;
    }

    public void setNode(int node) {
        this.node = node;
    }

    public String getArea() {
        return area;
    }

    public void setArea(String area) {
        this.area = area;
    }

    public String getDebtorName() {
        return debtorName;
    }

    public void setDebtorName(String debtorName) {
        this.debtorName = debtorName;
    }

    public String getAccountId() {
        return accountId;
    }

    public void setAccountId(String accountId) {
        this.accountId = accountId;
    }

    public String getDebtorId() {
        return debtorId;
    }

    public void setDebtorId(String debtorId) {
        this.debtorId = debtorId;
    }

    public String getCreditorId() {
        return creditorId;
    }

    public void setCreditorId(String creditorId) {
        this.creditorId = creditorId;
    }

    public String getCreditorName() {
        return creditorName;
    }

    public void setCreditorName(String creditorName) {
        this.creditorName = creditorName;
    }

    public List<Children> getChildren() {
        return children;
    }

    public void setChildren(List<Children> children) {
        this.children = children;
    }
}

class Chian {

    private double amount;
    private int node;
    private String area;
    private String debtorName;
    private String accountId;
    private String debtorId;
    private String creditorId;
    private List<Children> children;
    private String creditorName;

    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    public int getNode() {
        return node;
    }

    public void setNode(int node) {
        this.node = node;
    }

    public String getArea() {
        return area;
    }

    public void setArea(String area) {
        this.area = area;
    }

    public String getDebtorName() {
        return debtorName;
    }

    public void setDebtorName(String debtorName) {
        this.debtorName = debtorName;
    }

    public String getAccountId() {
        return accountId;
    }

    public void setAccountId(String accountId) {
        this.accountId = accountId;
    }

    public String getDebtorId() {
        return debtorId;
    }

    public void setDebtorId(String debtorId) {
        this.debtorId = debtorId;
    }

    public String getCreditorId() {
        return creditorId;
    }

    public void setCreditorId(String creditorId) {
        this.creditorId = creditorId;
    }

    public List<Children> getChildren() {
        return children;
    }

    public void setChildren(List<Children> children) {
        this.children = children;
    }

    public String getCreditorName() {
        return creditorName;
    }

    public void setCreditorName(String creditorName) {
        this.creditorName = creditorName;
    }
}

class Data {

    private String financeAmount;
    private double payAmount;
    private String area;
    private String userId;
    private int chainCount;
    private int seq;
    private String userName;
    private double receiveAmount;
    private List<Chian> chian;
    private double rongziAll;

    public String getFinanceAmount() {
        return financeAmount;
    }

    public void setFinanceAmount(String financeAmount) {
        this.financeAmount = financeAmount;
    }

    public double getPayAmount() {
        return payAmount;
    }

    public void setPayAmount(double payAmount) {
        this.payAmount = payAmount;
    }

    public String getArea() {
        return area;
    }

    public void setArea(String area) {
        this.area = area;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public int getChainCount() {
        return chainCount;
    }

    public void setChainCount(int chainCount) {
        this.chainCount = chainCount;
    }

    public int getSeq() {
        return seq;
    }

    public void setSeq(int seq) {
        this.seq = seq;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public double getReceiveAmount() {
        return receiveAmount;
    }

    public void setReceiveAmount(double receiveAmount) {
        this.receiveAmount = receiveAmount;
    }

    public List<Chian> getChian() {
        return chian;
    }

    public void setChian(List<Chian> chian) {
        this.chian = chian;
    }

    public double getRongziAll() {
        return rongziAll;
    }

    public void setRongziAll(double rongziAll) {
        this.rongziAll = rongziAll;
    }
}

class MyJson {

    private List<Data> datas;
    private String result;
    private int count;
    private String page;
    private String msg;

    public List<Data> getDatas() {
        return datas;
    }

    public void setDatas(List<Data> datas) {
        this.datas = datas;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public String getPage() {
        return page;
    }

    public void setPage(String page) {
        this.page = page;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}

只引用了fastjson

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.49</version>
 </dependency>
wushucheng18
诚哥丿 我丢, 怎么是安卓,没注意啊
大约一年之前 回复

直接使用Android studio的GsonFormat可以自动生成
public class demo {

/**
 * datas : [{"payAmount":0,"area":"滁州市","userId":"3638b61f7ef74d95ad6c14d8bc0644ff","chainCount":3,"seq":1,"userName":"还是收到","receiveAmount":7,"chian":[{"amount":7,"node":1,"area":"","debtorName":"还是","accountId":"AC20180810000616","debtorId":"43ded7a2d9b647d3bd1d8a5f7125dab4","creditorId":"3638b61f7ef74d95ad6c14d8bc0644ff","children":[{"amount":6,"node":2,"area":"","debtorName":"士大夫","accountId":"AC20180907000652","debtorId":"265581f4b83540a09cd8fba8797e7065","creditorId":"43ded7a2d9b647d3bd1d8a5f7125dab4","children":[],"creditorName":"还是"},{"amount":2,"node":2,"area":"","debtorName":"海阔天空","accountId":"AC20180912000657","debtorId":"a41dac80eaf940d58bcda3fe42faaaa3","creditorId":"43ded7a2d9b647d3bd1d8a5f7125dab4","children":[{"amount":4,"node":3,"area":"","debtorName":"士大夫","accountId":"AC20180907000651","debtorId":"265581f4b83540a09cd8fba8797e7065","creditorId":"a41dac80eaf940d58bcda3fe42faaaa3","children":[],"creditorName":"海阔天空"}],"creditorName":"还是"},{"amount":9.0E7,"node":2,"area":"","debtorName":"士大夫","accountId":"AC20180824000639","debtorId":"265581f4b83540a09cd8fba8797e7065","creditorId":"43ded7a2d9b647d3bd1d8a5f7125dab4","children":[],"creditorName":"还是"}],"creditorName":"还是收到"}],"rongziAll":9.0000008E7},{"financeAmount":0,"payAmount":0,"area":"抚顺市","userId":"3a33493363594bdfaa304586ab62668c","chainCount":0,"seq":2,"userName":"A","receiveAmount":0,"chian":"","rongziAll":0},{"payAmount":0,"area":"佳木斯市","userId":"c92fce2d51154fc597421c0c2d4f9171","chainCount":1,"seq":3,"userName":"阿甘船运有限公司","receiveAmount":1500000,"chian":[{"amount":1500000,"node":1,"area":"","debtorName":"澳洲太和矿业有限公司","accountId":"AC20180412000452","debtorId":"1acc2644a97541e5a9291120e379f416","creditorId":"c92fce2d51154fc597421c0c2d4f9171","children":[],"creditorName":"阿甘船运有限公司"}],"rongziAll":1500000},{"financeAmount":0,"payAmount":0,"area":"南昌市","userId":"1260d446161c4d7c8220e5addccc30ed","chainCount":0,"seq":4,"userName":"个人附件阿萨德","receiveAmount":0,"chian":"","rongziAll":0},{"financeAmount":0,"payAmount":0,"area":"伊犁哈萨克自治州","userId":"3fdc805022814024872428a5cefc9793","chainCount":0,"seq":5,"userName":"贺声耀","receiveAmount":0,"chian":"","rongziAll":0},{"payAmount":7,"area":"滁州市","userId":"43ded7a2d9b647d3bd1d8a5f7125dab4","chainCount":3,"seq":6,"userName":"还是","receiveAmount":9.0000008E7,"chian":[{"amount":6,"node":1,"area":"","debtorName":"士大夫","accountId":"AC20180907000652","debtorId":"265581f4b83540a09cd8fba8797e7065","creditorId":"43ded7a2d9b647d3bd1d8a5f7125dab4","children":[],"creditorName":"还是"},{"amount":2,"node":1,"area":"","debtorName":"海阔天空","accountId":"AC20180912000657","debtorId":"a41dac80eaf940d58bcda3fe42faaaa3","creditorId":"43ded7a2d9b647d3bd1d8a5f7125dab4","children":[{"amount":4,"node":2,"area":"","debtorName":"士大夫","accountId":"AC20180907000651","debtorId":"265581f4b83540a09cd8fba8797e7065","creditorId":"a41dac80eaf940d58bcda3fe42faaaa3","children":[],"creditorName":"海阔天空"}],"creditorName":"还是"},{"amount":9.0E7,"node":1,"area":"","debtorName":"士大夫","accountId":"AC20180824000639","debtorId":"265581f4b83540a09cd8fba8797e7065","creditorId":"43ded7a2d9b647d3bd1d8a5f7125dab4","children":[],"creditorName":"还是"}],"rongziAll":9.0000008E7},{"financeAmount":0,"payAmount":1500000,"area":"长春市","userId":"1acc2644a97541e5a9291120e379f416","chainCount":0,"seq":7,"userName":"澳洲太和矿业有限公司","receiveAmount":0,"chian":"","rongziAll":0},{"financeAmount":0,"payAmount":0,"area":"怀化市","userId":"7869179be7b74951994de20448970fe3","chainCount":0,"seq":8,"userName":"Shhshs","receiveAmount":0,"chian":"","rongziAll":0},{"payAmount":2,"area":"贵阳市","userId":"a41dac80eaf940d58bcda3fe42faaaa3","chainCount":1,"seq":9,"userName":"海阔天空","receiveAmount":4,"chian":[{"amount":4,"node":1,"area":"","debtorName":"士大夫","accountId":"AC20180907000651","debtorId":"265581f4b83540a09cd8fba8797e7065","creditorId":"a41dac80eaf940d58bcda3fe42faaaa3","children":[],"creditorName":"海阔天空"}],"rongziAll":4},{"financeAmount":0,"payAmount":9.000001E7,"area":"澳门","userId":"265581f4b83540a09cd8fba8797e7065","chainCount":0,"seq":10,"userName":"士大夫","receiveAmount":0,"chian":"","rongziAll":0}]
 * result : success
 * count : 10
 * page : 1
 * msg : 0
 */

private String result;
private int count;
private String page;
private String msg;
private List<DatasBean> datas;

public String getResult() {
    return result;
}

public void setResult(String result) {
    this.result = result;
}

public int getCount() {
    return count;
}

public void setCount(int count) {
    this.count = count;
}

public String getPage() {
    return page;
}

public void setPage(String page) {
    this.page = page;
}

public String getMsg() {
    return msg;
}

public void setMsg(String msg) {
    this.msg = msg;
}

public List<DatasBean> getDatas() {
    return datas;
}

public void setDatas(List<DatasBean> datas) {
    this.datas = datas;
}

public static class DatasBean {
    /**
     * payAmount : 0
     * area : 滁州市
     * userId : 3638b61f7ef74d95ad6c14d8bc0644ff
     * chainCount : 3
     * seq : 1
     * userName : 还是收到
     * receiveAmount : 7.0
     * chian : [{"amount":7,"node":1,"area":"","debtorName":"还是","accountId":"AC20180810000616","debtorId":"43ded7a2d9b647d3bd1d8a5f7125dab4","creditorId":"3638b61f7ef74d95ad6c14d8bc0644ff","children":[{"amount":6,"node":2,"area":"","debtorName":"士大夫","accountId":"AC20180907000652","debtorId":"265581f4b83540a09cd8fba8797e7065","creditorId":"43ded7a2d9b647d3bd1d8a5f7125dab4","children":[],"creditorName":"还是"},{"amount":2,"node":2,"area":"","debtorName":"海阔天空","accountId":"AC20180912000657","debtorId":"a41dac80eaf940d58bcda3fe42faaaa3","creditorId":"43ded7a2d9b647d3bd1d8a5f7125dab4","children":[{"amount":4,"node":3,"area":"","debtorName":"士大夫","accountId":"AC20180907000651","debtorId":"265581f4b83540a09cd8fba8797e7065","creditorId":"a41dac80eaf940d58bcda3fe42faaaa3","children":[],"creditorName":"海阔天空"}],"creditorName":"还是"},{"amount":9.0E7,"node":2,"area":"","debtorName":"士大夫","accountId":"AC20180824000639","debtorId":"265581f4b83540a09cd8fba8797e7065","creditorId":"43ded7a2d9b647d3bd1d8a5f7125dab4","children":[],"creditorName":"还是"}],"creditorName":"还是收到"}]
     * rongziAll : 9.0000008E7
     * financeAmount : 0
     */

    private int payAmount;
    private String area;
    private String userId;
    private int chainCount;
    private int seq;
    private String userName;
    private double receiveAmount;
    private double rongziAll;
    private int financeAmount;
    private List<ChianBean> chian;

    public int getPayAmount() {
        return payAmount;
    }

    public void setPayAmount(int payAmount) {
        this.payAmount = payAmount;
    }

    public String getArea() {
        return area;
    }

    public void setArea(String area) {
        this.area = area;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public int getChainCount() {
        return chainCount;
    }

    public void setChainCount(int chainCount) {
        this.chainCount = chainCount;
    }

    public int getSeq() {
        return seq;
    }

    public void setSeq(int seq) {
        this.seq = seq;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public double getReceiveAmount() {
        return receiveAmount;
    }

    public void setReceiveAmount(double receiveAmount) {
        this.receiveAmount = receiveAmount;
    }

    public double getRongziAll() {
        return rongziAll;
    }

    public void setRongziAll(double rongziAll) {
        this.rongziAll = rongziAll;
    }

    public int getFinanceAmount() {
        return financeAmount;
    }

    public void setFinanceAmount(int financeAmount) {
        this.financeAmount = financeAmount;
    }

    public List<ChianBean> getChian() {
        return chian;
    }

    public void setChian(List<ChianBean> chian) {
        this.chian = chian;
    }

    public static class ChianBean {
        /**
         * amount : 7.0
         * node : 1
         * area : 
         * debtorName : 还是
         * accountId : AC20180810000616
         * debtorId : 43ded7a2d9b647d3bd1d8a5f7125dab4
         * creditorId : 3638b61f7ef74d95ad6c14d8bc0644ff
         * children : [{"amount":6,"node":2,"area":"","debtorName":"士大夫","accountId":"AC20180907000652","debtorId":"265581f4b83540a09cd8fba8797e7065","creditorId":"43ded7a2d9b647d3bd1d8a5f7125dab4","children":[],"creditorName":"还是"},{"amount":2,"node":2,"area":"","debtorName":"海阔天空","accountId":"AC20180912000657","debtorId":"a41dac80eaf940d58bcda3fe42faaaa3","creditorId":"43ded7a2d9b647d3bd1d8a5f7125dab4","children":[{"amount":4,"node":3,"area":"","debtorName":"士大夫","accountId":"AC20180907000651","debtorId":"265581f4b83540a09cd8fba8797e7065","creditorId":"a41dac80eaf940d58bcda3fe42faaaa3","children":[],"creditorName":"海阔天空"}],"creditorName":"还是"},{"amount":9.0E7,"node":2,"area":"","debtorName":"士大夫","accountId":"AC20180824000639","debtorId":"265581f4b83540a09cd8fba8797e7065","creditorId":"43ded7a2d9b647d3bd1d8a5f7125dab4","children":[],"creditorName":"还是"}]
         * creditorName : 还是收到
         */

        private double amount;
        private int node;
        private String area;
        private String debtorName;
        private String accountId;
        private String debtorId;
        private String creditorId;
        private String creditorName;
        private List<ChildrenBean> children;

        public double getAmount() {
            return amount;
        }

        public void setAmount(double amount) {
            this.amount = amount;
        }

        public int getNode() {
            return node;
        }

        public void setNode(int node) {
            this.node = node;
        }

        public String getArea() {
            return area;
        }

        public void setArea(String area) {
            this.area = area;
        }

        public String getDebtorName() {
            return debtorName;
        }

        public void setDebtorName(String debtorName) {
            this.debtorName = debtorName;
        }

        public String getAccountId() {
            return accountId;
        }

        public void setAccountId(String accountId) {
            this.accountId = accountId;
        }

        public String getDebtorId() {
            return debtorId;
        }

        public void setDebtorId(String debtorId) {
            this.debtorId = debtorId;
        }

        public String getCreditorId() {
            return creditorId;
        }

        public void setCreditorId(String creditorId) {
            this.creditorId = creditorId;
        }

        public String getCreditorName() {
            return creditorName;
        }

        public void setCreditorName(String creditorName) {
            this.creditorName = creditorName;
        }

        public List<ChildrenBean> getChildren() {
            return children;
        }

        public void setChildren(List<ChildrenBean> children) {
            this.children = children;
        }

        public static class ChildrenBean {
            /**
             * amount : 6.0
             * node : 2
             * area : 
             * debtorName : 士大夫
             * accountId : AC20180907000652
             * debtorId : 265581f4b83540a09cd8fba8797e7065
             * creditorId : 43ded7a2d9b647d3bd1d8a5f7125dab4
             * children : []
             * creditorName : 还是
             */

            private double amount;
            private int node;
            private String area;
            private String debtorName;
            private String accountId;
            private String debtorId;
            private String creditorId;
            private String creditorName;
            private List<?> children;

            public double getAmount() {
                return amount;
            }

            public void setAmount(double amount) {
                this.amount = amount;
            }

            public int getNode() {
                return node;
            }

            public void setNode(int node) {
                this.node = node;
            }

            public String getArea() {
                return area;
            }

            public void setArea(String area) {
                this.area = area;
            }

            public String getDebtorName() {
                return debtorName;
            }

            public void setDebtorName(String debtorName) {
                this.debtorName = debtorName;
            }

            public String getAccountId() {
                return accountId;
            }

            public void setAccountId(String accountId) {
                this.accountId = accountId;
            }

            public String getDebtorId() {
                return debtorId;
            }

            public void setDebtorId(String debtorId) {
                this.debtorId = debtorId;
            }

            public String getCreditorId() {
                return creditorId;
            }

            public void setCreditorId(String creditorId) {
                this.creditorId = creditorId;
            }

            public String getCreditorName() {
                return creditorName;
            }

            public void setCreditorName(String creditorName) {
                this.creditorName = creditorName;
            }

            public List<?> getChildren() {
                return children;
            }

            public void setChildren(List<?> children) {
                this.children = children;
            }
        }
    }
}

}

嵌套for循环手动JSON来解析就行.类似递归

因为数据不确定,同一个字段对应的可能是JSONObject也可能是JSONArray,所以不好写java bean。只能手动递归解析,判断是object还是array循环解析

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
如何解析嵌套Json字符串,不使用第三方JAR
-
json解析格式问题。。。。。
-
JAVA 集合转JSON 嵌套循环
-
怎么递归json嵌套json?
-
Java解析嵌套json数据,嵌套结构怎么弄?
-
IOS5嵌套的json解析问题
-
多重循环是从里面到外读还是从外往里读,,,,,,,,循环嵌套
-
谁可以帮我解释下这个循环的嵌套么?最好来几个简单例题
-
函数和循环的类别是什么?为什么函数不能像循环那样嵌套调用呢?
-
java跳出嵌套循环的处理方法
-
关于json嵌套解析
-
Java Gson解析多层嵌套json字符串
-
如何在json格式里 嵌套一个json格式的数据
-
怎么判断是不是for循环嵌套
-
Action获取嵌套的json数据
-
【python】JSON嵌套字典循环替换值,并且作判断
-
未能解析类中的嵌套类型咋回事?
-
c++如何实现用函数递归进行多重循环嵌套
-
js 如何取到嵌套的json键值对的key?
-
程序员那些必须掌握的排序算法(下)
接着上一篇的排序算法,我们废话不多,直接进入主题。 1.快速排序 快速排序(Quicksort)是对冒泡排序的一种改进。 快速排序由C. A. R. Hoare在1960年提出。它的基本思想是:通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都要小,然后再按此方法对这两部分数据分别进行快速排序,整个排序过程可以递归进行,以此达到整个数据变成有序序列。 演示...
学会了这些技术,你离BAT大厂不远了
每一个程序员都有一个梦想,梦想着能够进入阿里、腾讯、字节跳动、百度等一线互联网公司,由于身边的环境等原因,不知道 BAT 等一线互联网公司使用哪些技术?或者该如何去学习这些技术?或者我该去哪些获取这些技术资料?没关系,平头哥一站式服务,上面统统不是问题。平头哥整理了 BAT 等一线大厂的必备技能,并且帮你准备了对应的资料。对于整理出来的技术,如果你掌握的不牢固,那就赶快巩固,如果你还没有涉及,现在...
程序员真是太太太太太有趣了!!!
网络上虽然已经有了很多关于程序员的话题,但大部分人对这个群体还是很陌生。我们在谈论程序员的时候,究竟该聊些什么呢?各位程序员大佬们,请让我听到你们的声音!不管你是前端开发...
史上最详细的IDEA优雅整合Maven+SSM框架(详细思路+附带源码)
网上很多整合SSM博客文章并不能让初探ssm的同学思路完全的清晰,可以试着关掉整合教程,摇两下头骨,哈一大口气,就在万事具备的时候,开整,这个时候你可能思路全无 ~中招了咩~ ,还有一些同学依旧在使用eclipse或者Myeclipse开发,我想对这些朋友说IDEA 的编译速度很快,人生苦短,来不及解释了,直接上手idea吧。这篇文章每一步搭建过程都测试过了,应该不会有什么差错。本文章还有个比较优秀的特点,就是idea的使用,基本上关于idea的操作都算是比较详细的,所以不用太担心不会撸idea!最后,本文
知乎上 40 个有趣回复,很精辟很提神
点击蓝色“五分钟学算法”关注我哟加个“星标”,天天中午 12:15,一起学算法作者 |佚名来源 |网络整理,版权归原作者所有,侵删。1交朋友的标准是什么?- Ques...
从入门到精通,Java学习路线导航
引言 最近也有很多人来向我"请教",他们大都是一些刚入门的新手,还不了解这个行业,也不知道从何学起,开始的时候非常迷茫,实在是每天回复很多人也很麻烦,所以在这里统一作个回复吧。 Java学习路线 当然,这里我只是说Java学习路线,因为自己就是学Java的,对Java理当很熟悉,对于其它方面,我也不是很了解。 基础阶段 首先是基础阶段,在基础阶段,我们必须掌握Java基础,Mysql数据库,Ora...
我花了一夜用数据结构给女朋友写个H5走迷宫游戏
起因 又到深夜了,我按照以往在csdn和公众号写着数据结构!这占用了我大量的时间!我的超越妹妹严重缺乏陪伴而 怨气满满! 而女朋友时常埋怨,认为数据结构这么抽象难懂的东西没啥作用,常会问道:天天写这玩意,有啥作用。而我答道:能干事情多了,比如写个迷宫小游戏啥的! 当我码完字准备睡觉时:写不好别睡觉! 分析 如果用数据结构与算法造出东西来呢? ...
实现 Java 本地缓存,该从这几点开始
缓存,我相信大家对它一定不陌生,在项目中,缓存肯定是必不可少的。市面上有非常多的缓存工具,比如 Redis、Guava Cache 或者 EHcache。对于这些工具,我想大家肯定都非常熟悉,所以今天我们不聊它们,我们来聊一聊如何实现本地缓存。参考上面几种工具,要实现一个较好的本地缓存,平头哥认为要从以下三个方面开始。 1、存储集合的选择 实现本地缓存,存储容器肯定是 key/value 形式的数...
揭开 Python 内存分配时的小秘密!
作者 | 豌豆花下猫 责编 | 胡巍巍 Python 中的sys模块极为基础而重要,它主要提供了一些给解释器使用(或由它维护)的变量,以及一些与解释器强交互的函数。 本文将会频繁地使用该模块的getsizeof()方法,因此,我先简要介绍一下: 该方法用于获取一个对象的字节大小(bytes) 它只计算直接占用的内存,而不计算对象内所引用对象的内存 这里有个直观的例...
让程序员崩溃的瞬间(非程序员勿入)
今天给大家带来点快乐,程序员才能看懂。 来源:https://zhuanlan.zhihu.com/p/47066521 1. 公司实习生找 Bug 2.在调试时,将断点设置在错误的位置 3.当我有一个很棒的调试想法时 4.偶然间看到自己多年前写的代码 5.当我第一次启动我的单元测试时 ...
用Python分析2000款避孕套,得出这些有趣的结论
到现在为止,我们的淘宝教程已经写到了第四篇,前三篇分别是: 第一篇:Python模拟登录淘宝,详细讲解如何使用requests库登录淘宝pc端。 第二篇:淘宝自动登录2.0,新增Cookies序列化,教大家如何将cookies保存起来。 第三篇:Python爬取淘宝商品避孕套,教大家如何爬取淘宝pc端商品信息。 今天,我们来看看淘宝系列的第四篇 我们在上一篇的时候已经将淘宝数据爬取下来了,...
做好以下四点,拒做 “ 空心 ” 程序员
01、注重原理性知识 现在的互联网环境下,注重原理性知识学习的程序员越来越少,特别是在这种培训机构大爆炸的环境下,在网上你会经常看到类似三个月从入门到精通高并发、分布式的广告,我相信培训机构有这套技术的能力,但是我不相信一个初学者有这么好的接收能力。甚至某个培训机构的讲师里,有一个1997年出生的架构师,20岁出头就当上了架构师,真的是后生可畏呀。在我的思维里,架构师不是学出来的,架构师是...
分享靠写代码赚钱的一些门路
作者 mezod,译者 josephchang10如今,通过自己的代码去赚钱变得越来越简单,不过对很多人来说依然还是很难,因为他们不知道有哪些门路。今天给大家分享一个精彩...
技术人员要拿百万年薪,必须要经历这9个段位
很多人都问,技术人员如何成长,每个阶段又是怎样的,如何才能走出当前的迷茫,实现自我的突破。所以我结合我自己10多年的从业经验,总结了技术人员成长的9个段位,希望对大家的职...
面试官:兄弟,说说基本类型和包装类型的区别吧
Java 的每个基本类型都对应了一个包装类型,比如说 int 的包装类型为 Integer,double 的包装类型为 Double。基本类型和包装类型的区别主要有以下 4 点。
进程和线程的区别(超详细)
进程和线程 进程 一个在内存中运行的应用程序。每个进程都有自己独立的一块内存空间,一个进程可以有多个线程,比如在Windows系统中,一个运行的xx.exe就是一个进程。 线程 进程中的一个执行任务(控制单元),负责当前进程中程序的执行。一个进程至少有一个线程,一个进程可以运行多个线程,多个线程可共享数据。 与进程不同的是同类的多个线程共享进程的堆和方法区资源,但每个线程有自己的程序计数器、虚拟...
第二弹!python爬虫批量下载高清大图
文章目录前言下载免费高清大图下载带水印的精选图代码与总结 前言 在上一篇写文章没高质量配图?python爬虫绕过限制一键搜索下载图虫创意图片!中,我们在未登录的情况下实现了图虫创意无水印高清小图的批量下载。虽然小图能够在一些移动端可能展示的还行,但是放到pc端展示图片太小效果真的是很一般!建议阅读本文查看上一篇文章,在具体实现不做太多介绍,只讲个分析思路。 当然,本文可能技术要求不是特别高,但可以...
面试官,不要再问我三次握手和四次挥手
三次握手和四次挥手是各个公司常见的考点,也具有一定的水平区分度,也被一些面试官作为热身题。很多小伙伴说这个问题刚开始回答的挺好,但是后面越回答越冒冷汗,最后就歇菜了。 见过比较典型的面试场景是这样的: 面试官:请介绍下三次握手 求职者:第一次握手就是客户端给服务器端发送一个报文,第二次就是服务器收到报文之后,会应答一个报文给客户端,第三次握手就是客户端收到报文后再给服务器发送一个报文,三次握手就...
为什么说 Web 开发永远不会退出历史舞台?
早在 PC 崛起之际,Web 从蹒跚学步一路走到了主导市场的地位,但是随着移动互联网时代的来临,业界曾有不少人猜测,“Web 应该被杀死,App 才是未来”。不过时间是检...
Java 爬虫遇到需要登录的网站,该怎么办?
这是 Java 网络爬虫系列博文的第二篇,在上一篇 Java 网络爬虫,就是这么的简单 中,我们简单的学习了一下如何利用 Java 进行网络爬虫。在这一篇中我们将简单的聊一聊在网络爬虫时,遇到需要登录的网站,我们该怎么办? 在做爬虫时,遇到需要登陆的问题也比较常见,比如写脚本抢票之类的,但凡需要个人信息的都需要登陆,对于这类问题主要有两种解决方式:一种方式是手动设置 cookie ,就是先在网站上...
nginx学习,看这一篇就够了:下载、安装。使用:正向代理、反向代理、负载均衡。常用命令和配置文件
文章目录前言一、nginx简介1. 什么是 nginx 和可以做什么事情2.Nginx 作为 web 服务器3. 正向代理4. 反向代理5. 动静分离6.动静分离二、Nginx 的安装三、 Nginx 的常用命令和配置文件四、 Nginx 配置实例 1 反向代理五、 Nginx 配置实例 2 负载均衡六、 Nginx 配置实例 3 动静分离七、 Nginx 的高可用集群 前言 一、nginx简介...
相关热词 c#二进制字符转字节 c# rc4 c#中md5加密 c# 新建mvc项目 c# 引用mysql c#动态加载非托管dll c# 两个表数据同步 c# 返回浮点json c# imap 链接状态 c# 漂亮字