Json格式字符串转Java对象
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json
免费下载资源
·
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 个月前
更多推荐
已为社区贡献3条内容
所有评论(0)