[英]How to retrieve the value of key "folderName" from the following JSON data in Flutter?
[英]how to view this json data in flutter with Map<key,value>
我正在将我的数据从这里获取到我的fetch数据类型中
Map fetch = new Map();
eos.Transaction transaction = eos.Transaction()..actions = actions;
_eosClient.pushTransaction(transaction, broadcast: true).then((trx) {
print(trx); //for printing in console
setState(() {
fetch = trx;
});
});
并试图在我的屏幕上显示这些数据
Expanded(
child: new ListView.builder(
itemCount: fetch.length,
itemBuilder: (BuildContext context, int index) {
String key = fetch.keys.elementAt(index);
return Column(
children: <Widget>[
Text(key),
Padding(
padding: const EdgeInsets.all(12.0),
child: Text(
'${fetch['processed']['action_traces']}',
),
),
],
);
}),
),
控制台中的数据如下所示,只想打印粗体数据
processed :{id: 93ae1319f9927becf0c164722fbb58a33518358e9b148f5af92140f6ab01543c, block_num: 51432026, block_time: 2019-09-25T06:21:11.000, producer_block_id: null, receipt: {status: executed, cpu_usage_us: 264, net_usage_words: 13}, elapsed: 264, net_usage: 104 , scheduled: false, action_traces : [{action_ordinal: 1, creator_action_ordinal: 0, closest_unnotified_ancestor_action_ordinal: 0, receipt: {receiver: guru11111111, act_digest: 55e9b8f98bde721c3f3e53cf98a20814a5d426290b0bf55f842d97866bc71f6c, global_sequence: 488625827, recv_sequence: 353, auth_sequence: [[guru11111111, 423]], code_sequence: 25, abi_sequence: 14}, receiver: guru11111111, act: {account: guru11111111, name: getborrower, 授权: [{actor: guru11111111, permission: active}], data: {acc_name: guru}, hex_data: 0000000000a0af66} , context_free: false, elapsed: 69, console: Borrower Name: guru ID: 1 Location: varanasi Phone Number: 8563070443 Loan amount: 4652007308841189376 , trx_id: 93ae1319f9927becf0c164722fbb58a33518358e9b148f
我试图让它看起来像这样
{
transaction_id: c459d2da5100afb1b4ab0352debfa4736aadd8c2e36529fe0861c9c8cadddeae,
processed: {
id: c459d2da5100afb1b4ab0352debfa4736aadd8c2e36529fe0861c9c8cadddeae,
block_num: 51299894,
block_time: 2019-09-24T11:40:11.500,
producer_block_id: null,
receipt: {
status: executed,
cpu_usage_us: 226,
net_usage_words: 13
},
elapsed: 226,
net_usage: 104,
scheduled: false,
action_traces: [
{
action_ordinal: 1,
creator_action_ordinal: 0,
closest_unnotified_ancestor_action_ordinal: 0,
receipt: {
receiver: guru11111111,
act_digest: 55e9b8f98bde721c3f3e53cf98a20814a5d426290b0bf55f842d97866bc71f6c,
global_sequence: 488304782,
recv_sequence: 329,
auth_sequence: [
[guru11111111, 399]
],
code_sequence: 25,
abi_sequence: 14
},
receiver: guru11111111,
act: {
account: guru11111111,
name: getborrower,
authorization: [
{
actor: guru11111111,
permission: active
}
],
data:
{
acc_name: guru
},
hex_data: 0000000000a0af66
},
context_free: false,
elapsed: 60,
console:
Borrower Name: guru
ID: 1
Location: varanasi
Phone Number: 8563070443,
Loan Amount:465200
}
文本('${fetch['processed']['action_traces']}'),
我可以打印到“action_traces”,但不能在“action_traces”内打印
在action_traces之后有一个数组,所以我给出了数组的索引,我们也可以为此使用 foreach 循环。
//Text('${fetch['processed']['action_traces'][0]['console']}',)
Expanded(
child: ListView.builder(
itemCount: fetch.length,
itemBuilder: (BuildContext context, int index) {
// String key = fetch.keys.elementAt(index);
print('${fetch[fetch.keys.elementAt(index)]}');
return Center(
child: Text(
'${fetch['processed']['action_traces'][0]['console']}',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
);
}),
)
首先,您需要创建正确的 model 来解析此 JSON,为此您可以使用 Dart 的官方 package json_annotation 。 After you have created model classes you will need to desrialise the json into Dart model and then use them as you want in your code.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.