org-json-parsetool - JSON转Java Bean工具


GPL
跨平台
Java

软件简介

一、简介

一款轻量级 Android JSONObject 转 Java Bean 工具,也可用于使用 org.json.* 包的 Java 工程。
GitHub地址:https://github.com/panxw/org-json-parsetool

二、示例

输入 jsonStr:

[
    {
        "name": "hello",
        "age": 1,
        "address": {
            "address": "number 1",
            "postcode": 434000
        },
        "datas": [
            {
                "width": 480,
                "length": 800,
                "shape": "retangle sape"
            },
            {
                "width": 540,
                "length": 960,
                "shape": "cycle sape"
            }
        ]
    }
]

输出

[Info [name=hello, age=1, address=Address [address=number 1, postcode=434000], datas=[Data [length=800, width=480, shape=retangle sape], Data [length=960, width=540, shape=cycle sape]]]]

Java
bean for jsonStr:

public class Info implements Serializable{
    private static final long serialVersionUID = -7128975465639889745L;
    public  String name;
    public Integer age;
    public Address address;
    public List datas;
    
    public Info() {
        super();
    }

    @Override
    public String toString() {
        return "Info [name=" + name + ", age=" + age + ", address=" + address + ", datas=" + datas + "]";
    }
}


public class Address implements Serializable {
    private static final long serialVersionUID = -5953347429635753009L;
    public String address;
    public Integer postcode;

    public Address() {
        super();
    }

    @Override
    public String toString() {
        return "Address [address=" + address + ", postcode=" + postcode + "]";
    }
}


public class Data implements Serializable {
    private static final long serialVersionUID = -2155648856259566537L;
    public Integer length;
    public Integer width;
    public String shape;
    
    public Data() {
        super();
    }
    
    @Override
    public String toString() {
        return "Data [length=" + length + ", width=" + width + ", shape=" + shape + "]";
    }
}

PS:
顺便宣传下自己的GitHub,https://github.com/panxw
欢迎来Follow~