如何与Java的Gson动态解析此JSON
我有以下JSON:
{
"BTC": {
"full_name": "Bitcoin TST",
"payin_enabled": true,
"payout_enabled": true,
"transfer_enabled": true,
"precision_transfer": "0.00000001",
"networks": [{
"network": "BTC",
"protocol": "OMNI",
"default": true,
"payin_enabled": true,
"payout_enabled": true,
"precision_payout": "0.00000001",
"payout_fee": "0.000725840000",
"payout_is_payment_id": false,
"payin_payment_id": false,
"payin_confirmations": 3
}]
},
"ETH": {
"full_name": "Ethereum TST",
"payin_enabled": true,
"payout_enabled": true,
"transfer_enabled": true,
"precision_transfer": "0.000000000001",
"networks": [{
"network": "ETHTEST",
"protocol": "",
"default": true,
"payin_enabled": true,
"payout_enabled": true,
"precision_payout": "0.000000000000000001",
"payout_fee": "0.003621047265",
"payout_is_payment_id": false,
"payin_payment_id": false,
"payin_confirmaIions": 2
}]
}
}
我需要在同一对象中与Gson一起动态解析BTC和ETH等。 我在Java课程中需要的结构将是以下内容:
private String symbol; //this would be BTC or ETH or MATIC
private String full_name;
谢谢!
I have the following JSON:
{
"BTC": {
"full_name": "Bitcoin TST",
"payin_enabled": true,
"payout_enabled": true,
"transfer_enabled": true,
"precision_transfer": "0.00000001",
"networks": [{
"network": "BTC",
"protocol": "OMNI",
"default": true,
"payin_enabled": true,
"payout_enabled": true,
"precision_payout": "0.00000001",
"payout_fee": "0.000725840000",
"payout_is_payment_id": false,
"payin_payment_id": false,
"payin_confirmations": 3
}]
},
"ETH": {
"full_name": "Ethereum TST",
"payin_enabled": true,
"payout_enabled": true,
"transfer_enabled": true,
"precision_transfer": "0.000000000001",
"networks": [{
"network": "ETHTEST",
"protocol": "",
"default": true,
"payin_enabled": true,
"payout_enabled": true,
"precision_payout": "0.000000000000000001",
"payout_fee": "0.003621047265",
"payout_is_payment_id": false,
"payin_payment_id": false,
"payin_confirmaIions": 2
}]
}
}
And I need to dynamically parse BTC and ETH and so on with GSON in the same object.
The structure I need in the java class would be the following:
private String symbol; //this would be BTC or ETH or MATIC
private String full_name;
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在高级别上使用
hashmap
,然后将其他JSON属性存储在
网络
class default均保留关键字@SerializedName(“ default”)正在处理
以进行测试的代码
Use
HashMap
at the high level and then store the other JSON properties in other classesHere in
Network
class default is reserved keyword@SerializedName("default")
that is being handled this wayCode to Test