Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.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
如何将多个解释为字符串的json对象转换为json字典_Json_Python 3.x - Fatal编程技术网

如何将多个解释为字符串的json对象转换为json字典

如何将多个解释为字符串的json对象转换为json字典,json,python-3.x,Json,Python 3.x,我的数据如下所示,看起来像多个json字典,但它是字符串类型。有人能帮我把它转换成json字典吗 {"id": "1305857561179152385", "tweet": "If you like vintage coke machines and guys who look like Fred Flintstone you'll love the short we've riffed: Coke R\u2026 &quo

我的数据如下所示,看起来像多个json字典,但它是字符串类型。有人能帮我把它转换成json字典吗

{"id": "1305857561179152385", "tweet": "If you like vintage coke machines and guys who look like Fred Flintstone you'll love the short we've riffed: Coke R\u2026 ", "ts": "Tue Sep 15 13:14:38 +0000 2020"}{"id": "1305858267067883521", "tweet": "Chinese unicorn Genki Forest plots own beverage hits  #China #Chinese #Brands #GoingGlobal\u2026 ", "ts": "Tue Sep 15 13:17:27 +0000 2020"}{"id": "1305858731293507585", "tweet": "RT @CinemaCheezy: If you like vintage coke machines and guys who look like Fred Flintstone you'll love the short we've riffed: Coke Refresh\u2026", "ts": "Tue Sep 15 13:19:17 +0000 2020"}
试试这个

let = "{'a': 'b', 'c': 'd'}{'e':'f', 'g':'h'}"
let_list = let.split('}')
d = []
for i in let_list[:-1]:
    val = eval(i + '}')
    d.append(val)
输出将是两个字典

print(d)
# Will print as shown
[{'a': 'b', 'c': 'd'}, {'e':'f', 'g':'h'}]

[错误]JSONDECODEROR:额外数据:第1行第228列(char 227)回溯(最后一次调用):文件“/var/task/lambda_function.py”,第36行,在lambda_处理程序jsonFile=json.loads(jsonremovebrace2)文件“/var/lang/lib/python3.8/json/u init_uu.py”,第357行,在加载返回_default_decoder.decode文件中“/var/lang/lib/python3.8/json/decoder.py”,第340行,在decode-raise-jsondecoderror(“额外数据”,s,end)end-RequestId:a00d25f0-112b-4f53-ab94-3e1cea72a23b这是我在代码之后得到的类型。我如何将其转换为类型?{'test':{'id':'1305858731293507585','tweet'”RT@CinemaCheezy:如果你喜欢老式的可乐机和像Fred Flintstone一样的家伙,你会喜欢我们翻唱的短片:《可乐刷新》。“ts”:“周二9月15日13:19:17+0000 2020”}它只给了我一本字典不是全部…我怎么才能得到所有的字典?如果你在列表上迭代,这里是
d
,你会得到所有的字典。它是字典列表
print(d)
# Will print as shown
[{'a': 'b', 'c': 'd'}, {'e':'f', 'g':'h'}]