package test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;

/**
 * Created by drguo on 2018/1/14.
 */
public class Jsonstr2Object {

    public static void main(String[] args){

        String str = "{\"Cover\":\"0\",\"Data\":\"data\",\"Type\":\"0\"}";

        Invoice invoice = JSONObject.parseObject(str, Invoice.class);

        System.out.println(invoice);

        String s = JSON.toJSONString(invoice);

        System.out.println(s);

        Invoice invoice1 = JSON.parseObject(str, Invoice.class);

        System.out.println(invoice1);

        String strJson = JSONObject.toJSONString(invoice1);

        System.out.println(strJson);


    }
}
class Invoice {

    private String Cover;

    private String Data;

    private String Type;

    @JSONField(name = "Cover")
    public String getCover() {
        return Cover;
    }

    @JSONField(name = "Cover")
    public void setCover(String cover) {
        Cover = cover;
    }

    @JSONField(name = "Data")
    public String getData() {
        return Data;
    }

    @JSONField(name = "Data")
    public void setData(String data) {
        Data = data;
    }

    @JSONField(name = "Type")
    public String getType() {
        return Type;
    }

    @JSONField(name = "Type")
    public void setType(String type) {
        Type = type;
    }

    @Override
    public String toString() {
        return "Invoice{" +
                "Cover='" + Cover + '\'' +
                ", Data='" + Data + '\'' +
                ", Type='" + Type + '\'' +
                '}';
    }
}
GitHub 加速计划 / js / json
41.72 K
6.61 K
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:1 个月前 )
960b763e 4 个月前
8c391e04 6 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐