英文:
How do I convert a string of a python dictionary to JSON object? json.loads() gives me a double quote error every time
问题
{
"intent": "catalog_search",
"id": 1,
"dependency": [],
"args": {
"text": "Could you please retrieve all table assets scanned before 1 hour?"
}
}
当我对其应用json.loads()
时,我收到错误信息:"json.decoder.JSONDecodeError: 期望属性名用双引号括起来:第1行第2列(字符1)"。是什么原因?所有的键明显都有双引号,是我的格式有问题吗?
我以为问题可能是开头和结尾的双大括号,但当我移除它们时,我得到了相同的结果。
英文:
I have this as a string:
{{
"intent": "catalog_search",
"id": 1,
"dependency": [],
"args": {{
"text": "Could you please retrieve all table assets scanned before 1 hour?"
}}
}}
When I apply json.loads() to it, I get the error "json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)". What gives? All of the keys clearly have double quotes, is my formatting wrong in some way?
I thought the issue might be the double curly brackets at the start and end, but I got the same result when I removed them.
答案1
得分: 1
所有双括号都需要更改为单括号。这是有效的:
{
"intent": "catalog_search",
"id": 1,
"dependency": [],
"args": {
"text": "Could you please retrieve all table assets scanned before 1 hour?"
}
}
英文:
All the double braces need to be changed to single braces. This is valid:
{
"intent": "catalog_search",
"id": 1,
"dependency": [],
"args": {
"text": "Could you please retrieve all table assets scanned before 1 hour?"
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论