简体   繁体   中英

Read specific JSON value with Python

In Python, if I use print cgminer.command('summary') I will get this output:

{u'STATUS': [{u'Code': 11,
   u'Description': u'cgminer 3.3.4',
   u'Msg': u'Summary',
   u'STATUS': u'S',
   u'When': 1378918507}],
 u'SUMMARY': [{u'Accepted': 69859,
   u'Best Share': 1498416,
   u'Device Hardware%': 0.0005,
   u'Device Rejected%': 0.3646,
   u'Difficulty Accepted': 209577.0,
   u'Difficulty Rejected': 768.0,
   u'Difficulty Stale': 0.0,
   u'Discarded': 12286,
   u'Elapsed': 193470,
   u'Found Blocks': 0,
   u'Get Failures': 2,
   u'Getworks': 6147,
   u'Hardware Errors': 1,
   u'Local Work': 259407,
   u'MHS av': 4676.09,
   u'Network Blocks': 371,
   u'Pool Rejected%': 0.3651,
   u'Pool Stale%': 0.0,
   u'Rejected': 256,
   u'Remote Failures': 1,
   u'Stale': 3,
   u'Total MH': 904683321.2956,
   u'Utility': 21.67,
   u'Work Utility': 65.32}],
 u'id': 1}

How can I make a new element like this:

accepted = 209577.0 (the value of Difficulty Accepted from the JSON result).

accepted = cgminer.command('summary')['SUMMARY'][0]['Difficulty Accepted']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM