在不确定的情况循环嵌套的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
诚哥丿 我丢, 怎么是安卓,没注意啊
12 个月之前 回复

直接使用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问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
java 解析不确定key的json
JSONObject  jsonObject Iterator it = jsonObject.keys(); List keys=new ArrayList(); while(it.hasNext()){                 String key = (String) it.next(); //             String value = jsonObject.g
fastjson解析map的循环嵌套json串
实体类: package com.site.utils; import java.util.List; /** * Create by szw on 2017/11/24 10:17 */ public class Life { private String name;//姓名 private int age;//年龄 private String count
json的key不确定时自动解析的方法
List&amp;lt;String&amp;gt; list = new ArrayList&amp;lt;String&amp;gt;(); try{ JSONObject json = new JSONObject(jsonss); JSONArray jsonArray =...
C# 如何实现循环嵌套次数不确定的问题
我的问题描述如下rn假设有n个数,每一个数取值范围已知(连续整数取值),列出这n个数的所有排列情况,例如,有a,b,c三个数,a取值为0~2,b取值为0~1,c取值为0~3,(abc均取整数),请列出abc的所有组合情况(数字顺序就是abc)。循环嵌套只能解决n给定且较小的问题,如果n不确定并较大时就不知道怎么弄了,求高手解答
这段json怎么解析
L.detal=rn"info": "name":"lzhr","noMark":false,"age":"28" ,rn"address":"ssadd":"广东","city":"yc",rn "school":["city":"yc","address":"河㙟","city":"yc","address":"阳春","city":"荆州","address":"荆州市"]rnrn怎么解析!谢谢
这段JSON怎么解析?
[rn rn "currentpage": "",rn "endNum": "",rn "firststrfind": "",rn "intPageCount": "",rn "intRowCount": "",rn "key": "302844008",rn "kind": "1",rn "startNum": "",rn "strfind": " jgdm='302844008'",rn "xzqhName": "alll"rn ,rn [rn rn "bzjgmcs": "福建省厦门市质量技术监督局",rn "bzrq": "2016-03-28",rn "entryJgdm": "",rn "jgdm": "302844006",rn "jgdz": "榔西里99号301室",rn "jglx": "企业法人 ",rn "jgmc": "厦门国易有限公司",rn "ly": "ZK_Y",rn "reservea": "91350203302944006K",rn "rowNum": "",rn "zch": "35020320048699",rn "zcrq": "2014-09-17",rn "zfrq": "2020-03-27"rn rn ]rn]rnrn我用LitJsonrn JsonData jm = JsonMapper.ToObject(json);rnrn好像下面这部分的得不到:rn [rn rn "bzjgmcs": "福建省厦门市质量技术监督局",rn "bzrq": "2016-03-28",rn "entryJgdm": "",rn "jgdm": "302844006",rn "jgdz": "榔西里99号301室",rn "jglx": "企业法人 ",rn "jgmc": "厦门国易有限公司",rn "ly": "ZK_Y",rn "reservea": "91350203302944006K",rn "rowNum": "",rn "zch": "35020320048699",rn "zcrq": "2014-09-17",rn "zfrq": "2020-03-27"rn rn ]
JSON 数据 怎么解析
我们现在时候WINFORM 项目 查询的是网页内容 返回的是JSON 怎么解析? 有什么第三方组件没有?
无名的json怎么解析?
做爬虫程序,很奇怪的一段json格式数据 如何解析呢?请教高手!rnrn[code=csharp]rn[rn rn "count": 1000rn ,rn [rn rn "sk": "001-s",rn "baobei": 1,rn ,rn rn "sk": "080-a",rn "baobei": 1,rn rn ]rn]rn[/code]rnrn如何书写序列化的类呢?
不确定key的json如何生成
对于json格式的传输,如果其中value也是json且其key的name 和数量都不确定,可以把不确定的json设为map进行然后把包含map的对象转换为json: 例如:要传送如下格式的json给服务端 { "speed":{ //速度时长 (速度:秒数) "30":"12", "40":"345", "60":"234" }, "hand":{ //左右手时长 "left"...
两个for循环嵌套两个for循环嵌套 应该怎么理解??
main() rn rn int i,j; rn printf(i j\n); rn for(i=0;i <2;i++) rn for(j=0;j <3;j++) rn printf(%d %d\n,i,j); rnrnrn输出结果为: rn i j rn 0 0 rn 0 1 rn 0 2 rn 1 0 rn 1 1 rn 1 2 rnrnrn这个题我怎么看 怎么不对! 我觉得输出结果应该为 rn i j rn 0 0 rn 1 1 rn 1 2
Json怎么解析下面的数据?
[code=csharp]rnrn "details": [rn rn "A": [rn [rn "老王",rn "60岁"rn ],rn [rn "老李",rn "72岁"rn ]rn ],rn "DataTime": 1389542400000,rn "B": [rn 0,rn 289277,rn 61086rn ],rn "C": [rn 26567,rn 27263rn ],rn "D": falsern ,rn rn ]rnrn[/code]rn以上数据怎么解析出来老王和老李的数据?
winfrom怎么解析这样的json
"message":"注册成功!","success":true,"code":null,"text":null
这个json要怎么解析?
["36801":"hhh","36802":"hop","36800":"pppp","36803":"jjjjj"]rn我要得到后面的hhh,hop,pppp,jjjjj这些数据我要怎么做???rn
求一段json怎么解析
"data":["trs":["tds":"binStatus":"value":"exception","capacityStatus":"value":"可回收:正常 其他:正常 ","waterStatus":"value":"N","batteryStatus":"value":"Y","typeCode":"value":"D-11","binImage":"value":null,"temperature":"value":"瓶子:0 可回收:0 其他:0 "],"name":"list","clazz":"Grid"]rnrnrn求获取到每一个value的值。我解析到trs的时候,获取的类型就是字符串了,不知道往下再如何解析了
这样结构的json怎么解析
[code=text]rn "response": rn "code": "1",rn "desc": "操作成功",rn "errorInfoList": null,rn "expressRoute": rn "expressName": "顺丰快递",rn "expressNo": "590176429594",rn "expressRouteItemList": rn "expressRouteItems": [rn rn "state": "10003",rn "notes": "海关已审批通过,海关进境清单编码为:JKE5141F506290011887 进境清关",rn "optime": "2015-06-29 18:53:05",rn "opercode": ""rn ,rn rn "state": "10001",rn "notes": "已收到订单信息,进境清关准备中 收到订单信息",rn "optime": "2015-07-13 13:33:00",rn "opercode": ""rn ,rn rn "state": "10003",rn "notes": "海关已审批通过,海关进境清单编码为:JKE5141F507130011269 进境清关",rn "optime": "2015-07-13 13:59:46",rn "opercode": ""rn ,rn rn "state": "10007",rn "notes": "仓库分拣包装完成,等待出库 分拣包装",rn "optime": "2015-07-13 17:18:32",rn "opercode": ""rn ,rn rn "state": "10009",rn "notes": "保税仓已放行成功,货品出区,交由国内配送服务商派送。 保税仓出区",rn "optime": "2015-07-14 12:17:00",rn "opercode": ""rn ,rn rn "state": "10010",rn "notes": "国内派送 国内派送",rn "optime": "2015-07-14 13:17:00",rn "opercode": ""rn ,rn rn "state": "50",rn "notes": "广州花都速配服务点 上门收件",rn "optime": "2015-07-14 14:17:00",rn "opercode": "50"rn ,rn rn "state": "3036",rn "notes": "广州花东服务点 快件在 广州花东服务点 ,准备送往下一站",rn "optime": "2015-07-14 17:31:00",rn "opercode": "3036"rn ,rn rn "state": "3036",rn "notes": "广州花都集散中心 到达..",rn "optime": "2015-07-14 19:03:00",rn "opercode": "3036"rn ,rn rn "state": "3036",rn "notes": "广州花都集散中心 快件在 广州花都集散中心 ,准备送往下一站",rn "optime": "2015-07-14 23:11:00",rn "opercode": "3036"rn ,rn rn "state": "3036",rn "notes": "杭州萧山集散中心 到达..",rn "optime": "2015-07-16 04:48:00",rn "opercode": "3036"rn ,rn rn "state": "3036",rn "notes": "上海浦江集散中心 快件在 上海浦江集散中心 ,准备送往下一站",rn "optime": "2015-07-16 08:53:00",rn "opercode": "3036"rn ,rn rn "state": "3036",rn "notes": "上海田林服务点 到达..",rn "optime": "2015-07-16 13:58:00",rn "opercode": "3036"rn ,rn rn "state": "3036",rn "notes": "上海田林服务点 快件在 上海田林服务点 ,准备送往下一站",rn "optime": "2015-07-16 14:40:00",rn "opercode": "3036"rn ,rn rn "state": "3036",rn "notes": "上海 到达..",rn "optime": "2015-07-16 14:57:00",rn "opercode": "3036"rn ,rn rn "state": "3036",rn "notes": "上海 便利店出仓",rn "optime": "2015-07-16 15:08:00",rn "opercode": "3036"rn ,rn rn "state": "70",rn "notes": "上海 由于 客户要求自取且已通知客户 派件不成功",rn "optime": "2015-07-16 15:13:00",rn "opercode": "70"rn ,rn rn "state": "70",rn "notes": "上海 由于 客户要求自取且已通知客户 派件不成功",rn "optime": "2015-07-17 09:09:00",rn "opercode": "70"rn ,rn rn "state": "70",rn "notes": "上海 由于 客户要求自取且已通知客户 派件不成功",rn "optime": "2015-07-17 19:03:00",rn "opercode": "70"rn ,rn rn "state": "70",rn "notes": "上海 由于 客户要求自取且已通知客户 派件不成功",rn "optime": "2015-07-18 15:26:00",rn "opercode": "70"rn ,rn rn "state": "70",rn "notes": "上海 由于 客户要求自取且已通知客户 派件不成功",rn "optime": "2015-07-19 10:09:00",rn "opercode": "70"rn ,rn rn "state": "70",rn "notes": "上海 由于 客户要求自取且已通知客户 派件不成功",rn "optime": "2015-07-19 19:35:00",rn "opercode": "70"rn ,rn rn "state": "70",rn "notes": "上海 由于 客户要求自取且已通知客户 派件不成功",rn "optime": "2015-07-20 08:23:00",rn "opercode": "70"rn ,rn rn "state": "70",rn "notes": "上海 由于 客户要求自取且已通知客户 派件不成功",rn "optime": "2015-07-21 09:02:00",rn "opercode": "70"rn ,rn rn "state": "80",rn "notes": "上海 派送成功",rn "optime": "2015-07-22 09:26:00",rn "opercode": "80"rn ,rn rn "state": "8000",rn "notes": "上海 在官网\"运单资料&签收图\",可查看签收人信息",rn "optime": "2015-07-22 09:26:00",rn "opercode": "8000"rn rn ]rn rn rn rn[/code]
这样的json该怎么解析?
通过Jquery的$.Ajax方法得到一个Json,将这个对象输出到屏幕上为:rnrn "Head":rn [rn rn "name":"aaa",rn "sex":"男",rn "age":"15",rn "date":"2009-6-29 23:00:44"rn , rn rn rn "name":"bbb",rn "sex":"男",rn "age":"21",rn "date":"2009-6-29 18:24:53"rn , rn rn rn "name":"ccc",rn "sex":"男",rn "age":"40",rn "date":"2009-6-29 18:18:12"rn rn ]rn rnrnrn请问这样该怎么解析呀???我新手,希望能给个实例~说详细点,谢谢了~~~
这Json应该怎么解析?
[rn [rn rn "id": 435224,rn "calcTime": "2016-03-16 20:20:52.0",rn "unit": null,rn "deviceCode": rn "id": 32,rn "devicename": "主机1"rn ,rn "value": 0rn ,rn rn "id": 435220,rn "calcTime": "2016-03-16 20:15:52.0",rn "unit": null,rn "deviceCode": rn "id": 32,rn "devicename": "主机1"rn ,rn "value": 0rn ,rn rn "id": 435216,rn "calcTime": "2016-03-16 20:10:52.0",rn "unit": null,rn "deviceCode": rn "id": 32,rn "devicename": "主机1"rn ,rn "value": 0rn ,rn rn "id": 435212,rn "calcTime": "2016-03-16 20:05:52.0",rn "unit": null,rn "deviceCode": rn "id": 32,rn "devicename": "主机1"rn ,rn "value": 0rn ,rn rn "id": 435208,rn "calcTime": "2016-03-16 20:00:52.0",rn "unit": null,rn "deviceCode": rn "id": 32,rn "devicename": "主机1"rn ,rn "value": 0rn rn ],rn [rn rn "id": 435225,rn "calcTime": "2016-03-16 20:20:52.0",rn "unit": null,rn "deviceCode": rn "id": 33,rn "devicename": "主机2"rn ,rn "value": 0rn ,rn rn "id": 435221,rn "calcTime": "2016-03-16 20:15:52.0",rn "unit": null,rn "deviceCode": rn "id": 33,rn "devicename": "主机2"rn ,rn "value": 0rn ,rn rn "id": 435217,rn "calcTime": "2016-03-16 20:10:52.0",rn "unit": null,rn "deviceCode": rn "id": 33,rn "devicename": "主机2"rn ,rn "value": 0rn ,rn rn "id": 435213,rn "calcTime": "2016-03-16 20:05:52.0",rn "unit": null,rn "deviceCode": rn "id": 33,rn "devicename": "主机2"rn ,rn "value": 0rn ,rn rn "id": 435209,rn "calcTime": "2016-03-16 20:00:52.0",rn "unit": null,rn "deviceCode": rn "id": 33,rn "devicename": "主机2"rn ,rn "value": 0rn rn ],rn [rn rn "id": 435226,rn "calcTime": "2016-03-16 20:20:52.0",rn "unit": null,rn "deviceCode": rn "id": 34,rn "devicename": "主机3"rn ,rn "value": 0rn ,rn rn "id": 435222,rn "calcTime": "2016-03-16 20:15:52.0",rn "unit": null,rn "deviceCode": rn "id": 34,rn "devicename": "主机3"rn ,rn "value": 0rn ,rn rn "id": 435218,rn "calcTime": "2016-03-16 20:10:52.0",rn "unit": null,rn "deviceCode": rn "id": 34,rn "devicename": "主机3"rn ,rn "value": 0rn ,rn rn "id": 435214,rn "calcTime": "2016-03-16 20:05:52.0",rn "unit": null,rn "deviceCode": rn "id": 34,rn "devicename": "主机3"rn ,rn "value": 0rn ,rn rn "id": 435210,rn "calcTime": "2016-03-16 20:00:52.0",rn "unit": null,rn "deviceCode": rn "id": 34,rn "devicename": "主机3"rn ,rn "value": 0rn rn ],rn [rn rn "id": 435227,rn "calcTime": "2016-03-16 20:20:52.0",rn "unit": null,rn "deviceCode": rn "id": 35,rn "devicename": "主机4"rn ,rn "value": 0rn ,rn rn "id": 435223,rn "calcTime": "2016-03-16 20:15:52.0",rn "unit": null,rn "deviceCode": rn "id": 35,rn "devicename": "主机4"rn ,rn "value": 0rn ,rn rn "id": 435219,rn "calcTime": "2016-03-16 20:10:52.0",rn "unit": null,rn "deviceCode": rn "id": 35,rn "devicename": "主机4"rn ,rn "value": 0rn ,rn rn "id": 435215,rn "calcTime": "2016-03-16 20:05:52.0",rn "unit": null,rn "deviceCode": rn "id": 35,rn "devicename": "主机4"rn ,rn "value": 0rn ,rn rn "id": 435211,rn "calcTime": "2016-03-16 20:00:52.0",rn "unit": null,rn "deviceCode": rn "id": 35,rn "devicename": "主机4"rn ,rn "value": 0rn rn ]rn]
这样形式的json怎么解析?
[code=javascript]rn "response":rn rn "result":true,rn "listResultEntry":[rn "id":3,"Desc":"~~~",rn "contentList":[rn "id":2,"No":123123,rn "id":3,"No":123123,rn "id":4,"No":123123,rn "id":5,"No":123123],rn "id":3,"name":"ee","telephone":"",rn ]rn rn[/code]
请问这个的json怎么解析
[code=php][rn rn "name": null,rn "id": "81",rn "title": "新版本",rn "body": "新版本预告",rn "user": "1",rn "addtime": "1411986371",rn "viewnum": "0"rn ,rn rn "name": null,rn "id": "80",rn "title": "谁见过",rn "body": "这里发内容无关人员看不到,哈哈",rn "user": "1",rn "addtime": "1411976785",rn "viewnum": "0"rn ,rn rn "name": null,rn "id": "79",rn "title": "阳光巴厘岛二期封顶",rn "body": "正式封顶",rn "user": "8",rn "addtime": "1411956282",rn "viewnum": "0"rn ,rn rn "name": null,rn "id": "37",rn "title": "传说",rn "body": "好多美女",rn "user": "1",rn "addtime": "1411715398",rn "viewnum": "0"rn ,rn rn "name": null,rn "id": "8",rn "title": "七月",rn "body": "七月,\r\n\r\n携着辉煌舞着夏风翩然而至,\r\n\r\n收获的歌声此起彼伏,\r\n\r\n果实的浓香在空气中荡漾。\r\n\r\n夏空中灿烂的彩霞,\r\n\r\n时时照入心灵的隧道,\r\n\r\n默默地触射在心底,\r\n\r\n淡淡的日子便有了简洁而深刻的诗意,\r\n\r\n没有那一段可以抹去的,\r\n\r\n只留下一些收藏。\r\n\r\n七月,\r\n\r\n是憩息的驿站,\r\n\r\n充满质感的光阴擦身而过,\r\n\r\n走向下一个季节的路上,\r\n\r\n留下一串串坚实的足迹,\r\n\r\n珍藏着一个个美丽的心情。",rn "user": "1",rn "addtime": "1408958408",rn "viewnum": "0"rn rn][/code]
怎么这样的json解析不了?
这个数据是从后台程序返回的"bool":"1","string":"\u6dfb\u52a0\u6210\u529f"rn从结构上没有什么不妥,但是用json_deconde解析不了rn
jQuery怎么解析 嵌套的JSON
JSON:rnrn[bureauID:"1",bureauName:"福田区",[wayId:"1",wayName:"富华三路",wayId:"2",wayName:"富华路",wayId:"3",wayName:"皇岗路",wayId:"4",wayName:"福田路"],bureauID:"2",bureauName:"罗湖区",[wayId:"5",wayName:"深南中路",wayId:"6",wayName:"水贝二路",wayId:"7",wayName:"笋岗东路",wayId:"8",wayName:"文锦北路",wayId:"9",wayName:"翠竹路"],bureauID:"3",bureauName:"南山区",[wayId:"10",wayName:"科苑南路",wayId:"11",wayName:"白石路",wayId:"12",wayName:"沙河西路"]]rnrnrn当AJAX返回一个二维的JSON时候,JQUERY 怎么解析?
.net 怎么解析这个Json
JSON示例: rnrnContent-type: text/html; charset=utf-8 rnrn"ret":0,rn"msg":"",rn"nickname":"Peter",rn"figureurl":"http://exmple.qq.com/qzapp/000000000000000000000000000F4262/50",rn rnrnqq登录 返回 的是这个JSon 怎么能获取 nickname和figureurl。谢谢大家帮个忙 看一下
没有键的json怎么解析?
奇葩的json格式,今天调试接口, 发现后台返回一段这样的json格式 看到这个图片数组,当时有点蛋疼,明明不是json格式的, 我以为json的数据类型, 全部都是键值对的, 后来上网查也没查到个所以然来,灵机一动, json,只有俩种格式, 对象和数组, 仔细观察,这个貌似也是数组,只是没有键而已,那是不是也可以当数组来处理呢。 于是乎,如下代码,果然可以解析成功。 String st
JSON解析 创建JSON
JSON解析 创建JSON
json常用方法,json解析
json包含常用的解析方法,包含常用方法说明,包含ajax和json的搭配使用。。。。
JSON 解析,JSON 数据
jSON
怎么判断是不是for循环嵌套
当程序中出现两个或两个以上for循环语句是,怎么判断是不是for循环嵌套?
循环嵌套
循环嵌套 1.温习一下循环三要素。 (1)定义一个初始值。 (2)表达式(条件) (3)增量(i++样式的) 2.循环嵌套 (1)简单来说就是循环里面再套一个循环。 (2)内循环循环一遍,外循环循环一下。举个小例子:内循环好似秒针, 外循环好似分针。秒针走一圈,分针走一下。 3.例子 (1)输出1-1000的素数: //循环出1-1000的数 for(int i=1;i
for循环嵌套
课程主要讲解了c语言数据与程序架构、函数、指针、数据结构等。<br /><br /><strong>学完本章能掌握什么:</strong><br /><p>n 增强对C语言的了解,为用户后期基于C语言的开发工作做准备。n</p>n<p>n <br /></p>n<p>n <strong>学习难度:</strong>基础n</p>
hive 解析json 之 json 中(key 不确定名称及个数, values 不确定数值及个数) 情况下解析
json 串如下所显示  repayment  list 中,有 多个 maps ,其中个maps中的key 是不确定个数的,半年是7个,2个月就是3个. &quot;repayment&quot;:{ &quot;credit_rpy_amt&quot;:{ &quot;2018-11&quot;:&quot;0.00&quot;, &quot;2018-10&quot;:&quot;0.00&quot;, &quot;2018-09&quot;:&quot;0.00&quot;, &quot;
XML文件的解析和json的解析
解析就是从事先规定好的格式中提取数据 XML的解析方式有两种 SAX解析 DCM解析(安卓有一个PULL) SAX解析: NSString *path = [[NSBundle mainBundle] pathForResource:@"Message" ofType:@"txt"]; NSData *data = [NSData dataWithContentsOfFile:
JSON解析之原生解析
JSON解析之原生解析 JSON是首先一种数据结构,说白了就是对数据的描述,刚刚出现是为了取代XML可惜并没有,但是在做为配置文件上,却是很好,由于它小巧灵活 描述数据很好,所以在网络上进行数据传输更加方便请记住JSON对数据的描述形式,既然是形式,那么它的数据形式是什么样的: 对象的描述是: {} 数组的描述是: [] 属性或值的描述是: “” 连接之间的描述是: : 比如 : {
Gson解析和json解析
json数据的简单介绍:json数据是一种轻量级的数据交换格式,一键值对的形式表现的。用[]括起来的可以理解为数组、用{}括起来的可以理解为对象。例如://对象 { "id":123, "username":"ws", "password":"admin", "phone":"15333333333" } //数组[{ "id":123, "username":"ws",
XML的解析与JSON解析
XML的解析 XML是一种常见的存储数据方式,在Android平台中内部很多地方都使用了XML存储,如轻量级的SharedPreferences类的存储就是使用的XML文件。 XML解析主要有三种方式,SAX(Simple API for XML),DOM(Document Object Mode)和Android附带的PULL解析器解析XML文件。 优点 缺点 SAX 读取为单...
XML解析、Json解析
XML解析一般分为SAX和DOM.也就是事件和文档. 一.XML解析之SAX解析, 及NSXMLParser SAX解析说白了就是事物模型解析, 从头开始读取文档, 读完头标签后, 理论上是读取标签值, 最后是结束标签 在ParserTool.h文件中// 这个是系统提供给的xml的解析方法, 通过代理方法完成解析 @interface ParserTool : NSObject<NSXML
JSON解析之手动解析
1、JSON简介 1)概念: JSON的全称是JavaScript Object Notation,是一种轻量级的数据交换格式。 2)特点: (1)本质就是具有特定格式的字符串 (2)JSON完全独立于编程语言 (3)JSON比XML数据传输的有效性要高出很多。 2、JSON数据格式 1)整体结构 String json1 = "{"id":12,"name":"Tom"}";
json解析之gson解析
我们知道在json中的两个基本结构是数组和对象,数组以[]括起来,数组里的值可以是数字、字符串、数组、对象几种;对象以{}括起来,对象中的数据是以键值对的形式出现的,键名就是属性名,键值就是属性值,属性值的类型可以是 数字、字符串、数组、对象几种。 如果解析的json是一个对象,那么我们建一个这样的类并以键名作为属性名类型为属性值类型。如果属性值是一个数组,那就建立一个List属性,例如下面
JSON的解析与反解析
JSON.h #ifndef __JSON__H__ #define __JSON__H__ #include &lt;stdio.h&gt; typedef enum //表示7种数据类型 { LEPT_NULL, //null LEPT_FALSE, //false LEPT_TRUE, //true LEPT_NUMBER,//数字 LEPT_STRING,//...
json解析封装和解析
{ "msgtype":1, "id":"1,2", "person":[ { "username":"zpq", "password":"zpq", "client":1 } ,{ "username":"zxx", "password":"zxx", "client":1 }] } 封装和解析
JSON解析/XML解析
主要是显示地理位置和天气以及温度。对网络请求下来的json数据进行解析。#import "ViewController.h" #define kWeatherUrl @"http://www.weather.com.cn/data/cityinfo/101010100.html"@interface ViewController ()<NSURLConnectionDataDelegate>{
相关热词 c++和c#哪个就业率高 c# 批量动态创建控件 c# 模块和程序集的区别 c# gmap 截图 c# 验证码图片生成类 c# 再次尝试 连接失败 c#开发编写规范 c# 压缩图片好麻烦 c#计算数组中的平均值 c#获取路由参数