所以我尝试读取这样的 json 文件:
{
"Name": "hello",
"Source": " import json \n x= 10, .... "
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用 python 中的 json 库来读取它的方式,因此我的代码看起来像这样:
import json
input =''' {
"Name": "python code",
"Source": " import json \n x= 10, .... "
}'''
output = json.load(input)
print(output)
Run Code Online (Sandbox Code Playgroud)
源有无效字符“\n”的问题。我不想用 \n 替换 \n,因为这是代码稍后将在另一个程序中运行。我知道 json.JSONDecoder 能够处理 \n 但我不知道如何使用。