Python-多系列JSON数据

Python-多系列JSON数据,python,json,parsing,Python,Json,Parsing,我有一些数据放在一个名为text.json的文件中 我怎么能读这个 我尝试将其解析为普通JSON,但出现错误: [ { "account" : "", "address" : "DD741HcHii8vq4fzPH58UDU7virAvtYyJf", "category" : "send", "amount" : -9.00000000, "fee" : -1.00000000, "confirmations" : 316, "

我有一些数据放在一个名为text.json的文件中

我怎么能读这个

我尝试将其解析为普通JSON,但出现错误:

   [
   {
    "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
    }
    ]
如果我真的能找到一种阅读的方式,我可以这样做:

    "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;
文件“th.py”,第12行,在
本地=数据[输入]
TypeError:列表索引必须是整数,而不是str

问题不在于解析,而在于访问解析后的数据。您的数据是一个目录列表。因此,不能直接使用字符串键访问它<代码>数据['blockindex']不存在:只有
数据[0]['blockindex']
数据[1]['blockindex']
,等等。

您使用的解析器是什么?我使用了Python的stock one(只是
import json
),它工作了…
import json
,然后
将open('text.json')作为f:my_json=json.load(f)
,这不会给出错误。请显示给出错误的确切命令,加上回溯。我已经用我的确切代码更新了我的OP。哦,太棒了。顺便说一下,数据[0][blockindex]在没有引号的情况下运行良好。我能看到“blockindex”有多少条记录吗?知道了,打印len(数据)
File "th.py", line 12, in <module>
local = data[input]
TypeError: list indices must be integers, not str