-1

我有这个方法:

lines = rec.split("\n")
rec = ''
size = len(lines)
i=0
for line in lines:
    try:
        self.on_data(json.load(line))
    except:
        logging.warning ('warning, could not parse line:', line)
        if i == size - 1:
            # if it is the last element, we can keep it, since it might not be complete
            rec+=line
    finally:
        i += 1

我收到此错误:

Message: 'warning, could not parse line:'
Arguments: ('{"readersCount":0,"uuid":"17f5fe87-5140-4f34-ac32-d325beb6b2a1","key":"bar","lockRequestCount":0,"type":"lock","acquired":true}',)

看起来我需要阅读元组的第一个元素还是什么?JSON看起来还可以吗?

4

1 回答 1

0

如评论中所述,您需要self.on_data(json.loads(line))

lines = rec.split("\n")
rec = ''
size = len(lines)
i=0
for line in lines:
    try:
        self.on_data(json.loads(line))
    except:
        logging.warning ('warning, could not parse line:', line)
        if i == size - 1:
            # if it is the last element, we can keep it, since it might not be complete
            rec+=line
    finally:
        i += 1
于 2019-03-12T07:49:32.650 回答