【发布时间】:2021-11-20 06:51:05
【问题描述】:
我想将任何对象序列化为 json 字符串。
例如我在成功购买后收到的 PurchaseDetails 对象。
结构如下:
/// Represents the transaction details of a purchase.
class PurchaseDetails {
PurchaseDetails({
this.purchaseID,
required this.productID,
required this.verificationData,
required this.transactionDate,
required this.status,
});
final String? purchaseID;
final String productID;
final PurchaseVerificationData verificationData;
final String? transactionDate;
PurchaseStatus status;
IAPError? error;
bool pendingCompletePurchase = false;
}
我们的后端已请求此输出为 JSON,我只需要一种快速的方法来解析它。
有没有这样的方法,如果没有,从第三方库序列化类时的最佳做法是什么?
【问题讨论】:
-
我真的只需要在调试并遇到断点时执行一次,但我无法从
Debug部分的variables选项卡中将值复制为Json。如果我能以编程方式完成它会更好,因为它在许多场景中都很有用。
标签: json flutter dart serialization in-app-purchase