我正在使用 python 3.9
我收到此錯誤:
json.decoder.JSONDecodeError: Expecting value: line 1 column 2 (char 1)
當我嘗試這樣做時:
import json
print(json.loads("['product', 'font', 'graphics', 'photo caption', 'brand', 'advertising', 'technology', 'text', 'graphic design', 'competition']"))
但是當我這樣做時它作業正常:
print(json.loads('["a", "b", "c"]'))
似乎錯誤與引號相關聯。但我可以問這是為什么嗎?謝謝!
uj5u.com熱心網友回復:
簡短的回答是這正是 JSON 規范的作業方式。從介紹 JSON中間的圖中可以看出,所有字串都必須用雙引號引起來。
但是,您可以在 python 中使用ast.literal_eval()而不是json.loads().
import ast
print(ast.literal_eval("['product', 'font', 'graphics', 'photo caption', 'brand', 'advertising', 'technology', 'text', 'graphic design', 'competition']"))
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/443921.html
下一篇:從S3訪問Zip檔案
