[
{
"account" : "",
"address" : "DD741HcHii8vq4fzPH58UDU7virAvtYyJf",
"category" : "send",
"amount" : -9.00000000,
"fee" : -1.00000000,
"confirmations" : 316,
"blockhash" : "9546b8d336c74222040b85a0a760c4c3dc4d5b744e0072fc1551f56f20472739",
"blockindex" : 31,
"blocktime" : 1394208201,
"txid" : "45f80847a45eab62189759eb9da30f40052c581ea06ca062ac155bbf563b907d",
"time" : 1394208153,
"timereceived" : 1394208153
},
{
"account" : "",
"address" : "DD741HcHii8vq4fzPH58UDU7virAvtYyJf",
"category" : "send",
"amount" : -0.04063000,
"fee" : -2.00000000,
"confirmations" : 313,
"blockhash" : "27cd2b1f380a651f78f83ef4deaaaf6a220028fe09b4219207ad5efecc69a29f",
"blockindex" : 7,
"blocktime" : 1394208392,
"txid" : "af48a278c3559f1c36a2fccda42ba35cc62c2083fa5959a567f6b4d4a4a594a7",
"time" : 1394208388,
"timereceived" : 1394208388
}
]
我有一些数据放在一个叫做文本.json你知道吗
我怎么能读这个?你知道吗
我尝试将其作为普通JSON进行解析,但得到错误:
"list indices must be integer, not str"
如果我真的找到了阅读的方法,我可以这样做:
getAmountOfRecords("blockindex")
JSON.parse[blockindex[0]] (returning 31)
JSON.parse[blockindex[1]] (returning 7)
谢谢:)
编辑:
我的代码是:
import os
import json
from pprint import pprint
os.system("dogecoind listtransactons > text.json")
with open('text.json') as f:
data = json.load(f)
input = raw_input('Enter a getter\n')
local = data[input]
print local;
回溯是:
File "th.py", line 12, in <module>
local = data[input]
TypeError: list indices must be integers, not str
问题不在于解析,而在于访问解析的数据。你的数据是一个目录列表。因此,不能使用字符串键直接访问它。
data['blockindex']
不存在:只有data[0]['blockindex']
、data[1]['blockindex']
,依此类推。你知道吗相关问题 更多 >
编程相关推荐