JSONDecodeError:应为值:第2行第1列(字符2)

2024-05-20 19:34:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我的函数如下所示:

filename = 'orderbook_file.json'

def get_line():
    f = open(filename, 'r')

    n_display = 0

    for line in f:
        data = json.loads(line)
        print(data)
        #if n_display % 100: continue
        n_display +=1
    return data

我的json对象如下所示:

[
{ 
    "asks" : [
        [
            0.00276477, 
            NumberInt(9)
        ]
    ], 
    "bids" : [
        [
            0.002755, 
            NumberInt(544)
        ]
    ], 
    "lastUpdated" : 1538582700048.0
},
{ 
    "asks" : [
        [
            0.00276477, 
            NumberInt(9)
        ]
    ], 
    "bids" : [
        [
            0.002755, 
            NumberInt(544)
        ]
    ], 
    "lastUpdated" : 1538582700048.0
}
]

我在尝试加载json时收到了标题中的错误。该文件基本上是一个json对象数组。我对Json不是很熟悉,有什么帮助吗?谢谢


Tags: 对象函数jsondatagetdefdisplayline