首页 > 解决方案 > JSONDecodeError:期望值:第 2 行第 1 列(字符 2)

问题描述

我的功能如下所示:

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不是很熟悉,有什么帮助吗?谢谢!

标签: pythonjson

解决方案


推荐阅读