Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JSONDecodeError:以Python开头的未终止字符串,即使我尝试使用strict=False来忽略/n之类的字符_Python_Json_Spyder_Data Analysis - Fatal编程技术网

JSONDecodeError:以Python开头的未终止字符串,即使我尝试使用strict=False来忽略/n之类的字符

JSONDecodeError:以Python开头的未终止字符串,即使我尝试使用strict=False来忽略/n之类的字符,python,json,spyder,data-analysis,Python,Json,Spyder,Data Analysis,这是我的密码: import json path = 'usagov_bitly_data2012-03-16-1331923249.txt' print(open(path).readline()) records = [json.loads(line,strict=False) for line in open(path)] print(records[0]) 我收到一条错误消息,名为jsondecoderror:Unterminated string,从开始。我正在使用json模块使用p

这是我的密码:

import json
path = 'usagov_bitly_data2012-03-16-1331923249.txt'
print(open(path).readline())
records = [json.loads(line,strict=False) for line in open(path)]
print(records[0])
我收到一条错误消息,名为
jsondecoderror:Unterminated string,从
开始。我正在使用
json
模块使用python逐行读取json文件

我无法获得预期的输出。有人能帮忙解决这个问题吗?

你好,试试这个

import json
path = 'usagov_bitly_data2012-03-16-1331923249.txt'
print(open(path).readline())
records = [json.dumps(line) for line in open(path)]
final_records = [json.loads(lines) for lines in records]
print(final_records[0])

您是否能够提供您正在使用的JSON文件(或文件片段)?这是我用来获取JSON文件的链接。它可以工作,但为什么在final_records语句中使用line而不是line呢?因为这是JSON.loads@AasikMohamed的另一个循环