java - 如何将字符串 JSON 格式拆分为 Java 中对象的构造函数?
问题描述
我有一个 java 类Payment.java
,它用 5 个构造函数和所需的 setter/getter 构造“支付”对象,如下所示:
public class Payment {
//Contractors
private Double amount, fee;
private String TXID;
private int time, type;
public Payment(Double amount, Double fee, String TXID, int time, int type) {
this.amount = amount;
this.fee = fee;
this.TXID = TXID;
this.time = time;
this.type = type;
}
public Double getAmount() {
return amount;
}
public void setAmount(Double value) {
this.amount = value;
}
public Double getFee() {
return fee;
}
public void setFee(Double value) {
this.fee = value;
}
public String getTXID() {
return TXID;
}
public void setTXID(String value) {
this.TXID = value;
}
public int getTime() {
return time;
}
public void setTime(int value) {
this.time = value;
}
public int getType() {
return type;
}
public void setType(int value) {
this.type = value;
}
}
HTTP(GET)
我有另一种方法,它向外部 API发送请求并JSON
以字符串格式返回结果,如下所示:
{
"result" : {
"nh_wallet" : true,
"payments" : [
{
"amount" : "0.00322253",
"fee" : "0.00006577",
"TXID" : "",
"time" : 1533114558,
"type" : 1
},
{
"amount" : "0.00273396",
"fee" : "0.0000558",
"TXID" : "",
"time" : 1533029140,
"type" : 1
},
{
"amount" : "0.00284428",
"fee" : "0.00005805",
"TXID" : "",
"time" : 1532944513,
"type" : 1
},
{
"amount" : "0.00213709",
"fee" : "0.00004361",
"TXID" : "",
"time" : 1532856970,
"type" : 1
}
],
"base64MarchantID" : "366GT4q6hw7cVN6zzkFWfqZeKHHXZCp4rA"
},
"method" : "stats.provider.payments"
}
假设 JSON 结果字符串实际上是一个动态<List>Payment
的,将这个字符串动态拆分为多个拆分的“付款”的最佳方法是什么?
解决方案
推荐阅读
- python - 使用python 3.6版在jetbrains pycharm中安装wordcloud失败
- c# - 将 2 个转换为 int 的数组字符串加在一起时出现我不明白的错误
- google-app-engine - 如何查看 App Engine 上的每日实例使用情况?
- git - 如何压缩来自将另一个 repo 集成到分支中的旧提交?
- java - 在 JAVA 中将无效字符串传递给 SimpleDateFormat 时引发异常
- apache-kafka - Kafka生产者回调异常
- android - 如何从 webview android 中获取所有 cookie 数据?
- java - Ambari Admin View 2.7.5.0.0 构建失败
- nestjs - 如何使用lerna 管理nestJS 项目?
- office-js - 如何使用刷新令牌在 Excel 加载项中使用 OfficeJS 获取新的访问令牌