2013-12-20 46 views
0

閱讀特定JSON值在Python,如果我用print cgminer.command('summary')我會得到這樣的輸出:我怎樣才能讓這樣的新元素與Python

{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結果)。

+0

這不是JSON(也許是在解析之前)。它是一本字典......所以只要把它用作字典。 – JBernardo

回答

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