Android Studio 自动生成JavaBean插件-GsonFormat
步骤:
1. 下载GsonFormat.jar ,下载地址:https://plugins.jetbrains.com/plugin/7654-gsonformat/versions 选择Android Studio,Download进行下载
2.AS-File-Setting-Plugins-Install Plugins from Disk (设置图标)-添加已经下载好的GsonFormat.jar 文件 ,重启Android Studio
3.使用:ALT + INS ,选择GsonFormat 自动生成
需要注意的是:服务器有时会返回一些特别的数据,比如:
{
"data": {
"2020": {
"3": {
"detail": [
{
"bank_id": "CCB",
"bank_name": "中国建设银行",
"card_num": "6217001210067335016",
"recharge_amount": "0.02",
"recharge_time": "1585559580",
"transaction_id": "1000115855598400555957888830482",
"user_id": "555984"
},
{
"bank_id": "CCB",
"bank_name": "中国建设银行",
"card_num": "6217001210067335016",
"recharge_amount": "0.02",
"recharge_time": "1585559505",
"transaction_id": "1000115855598400555950453325196",
"user_id": "555984"
},
{
"bank_id": "CCB",
"bank_name": "中国建设银行",
"card_num": "6217001210067335016",
"recharge_amount": "0.02",
"recharge_time": "1585559468",
"transaction_id": "1000115855598400555946814464581",
"user_id": "555984"
},
{
"bank_id": "CCB",
"bank_name": "中国建设银行",
"card_num": "6217001210067335016",
"recharge_amount": "0.02",
"recharge_time": "1585559447",
"transaction_id": "1000115855598400555944674404579",
"user_id": "555984"
},
{
"bank_id": "CCB",
"bank_name": "中国建设银行",
"card_num": "6217001210067335016",
"recharge_amount": "0.02",
"recharge_time": "1585559005",
"transaction_id": "1000115855598400555899936310856",
"user_id": "555984"
}
],
"total_amount": "0.10"
},
"4": {
"detail": [
{
"bank_id": "CCB",
"bank_name": "中国建设银行",
"card_num": "6217001210067335016",
"recharge_amount": "0.10",
"recharge_time": "1586962136",
"transaction_id": "1000115855598400496213567390918",
"user_id": "555984"
},
{
"bank_id": "CCB",
"bank_name": "中国建设银行",
"card_num": "6217001210067335016",
"recharge_amount": "0.30",
"recharge_time": "1585951939",
"transaction_id": "1000115855598400495193648999875",
"user_id": "555984"
}
],
"total_amount": "0.40"
}
}
},
"error_code": "",
"msg": "",
"status": "success"
}
这个时候咱们选择的数据是:
{
"detail": [
{
"bank_id": "CCB",
"bank_name": "中国建设银行",
"card_num": "6217001210067335016",
"recharge_amount": "0.02",
"recharge_time": "1585559580",
"transaction_id": "1000115855598400555957888830482",
"user_id": "555984"
},
{
"bank_id": "CCB",
"bank_name": "中国建设银行",
"card_num": "6217001210067335016",
"recharge_amount": "0.02",
"recharge_time": "1585559505",
"transaction_id": "1000115855598400555950453325196",
"user_id": "555984"
},
{
"bank_id": "CCB",
"bank_name": "中国建设银行",
"card_num": "6217001210067335016",
"recharge_amount": "0.02",
"recharge_time": "1585559468",
"transaction_id": "1000115855598400555946814464581",
"user_id": "555984"
},
{
"bank_id": "CCB",
"bank_name": "中国建设银行",
"card_num": "6217001210067335016",
"recharge_amount": "0.02",
"recharge_time": "1585559447",
"transaction_id": "1000115855598400555944674404579",
"user_id": "555984"
},
{
"bank_id": "CCB",
"bank_name": "中国建设银行",
"card_num": "6217001210067335016",
"recharge_amount": "0.02",
"recharge_time": "1585559005",
"transaction_id": "1000115855598400555899936310856",
"user_id": "555984"
}
],
"total_amount": "0.10"
}
注意:这个时候只能对以上的数据进行使用插件生成,其他数据不可以生成。
也就是说:对于数个元素对象Object,只选择其中一个对象Object进行封装Bean 对象即可;