As mentioned in this StackOverflow question, you are not allowed to have any trailing commas in json. For example, this
{
"key1": "value1",
"key2": "value2"
}
is fine, but this
{
"key1": "value1",
"key2": "value2",
}
is invalid syntax.
出于this other StackOverflow question中提到的原因,使用逗号结尾是合法的(也许是受鼓励的?)在Python代码中.我同时使用Python和JSON,所以我希望能够在这两种类型的文件中保持一致.有没有办法让json.loads
忽略尾随的逗号?