使用Python读取特定的JSON值

时间:2013-12-20 02:54:29

标签: python json

在Python中,如果我使用print cgminer.command('summary'),我将得到此输出:

{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}

如何制作这样的新元素:

accepted = 209577.0(从JSON结果中接受的难度值)。

1 个答案:

答案 0 :(得分:2)

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