如何将Python字典字符串转换为JSON对象?json.loads()每次都会报双引号错误。

huangapple go评论100阅读模式
英文:

How do I convert a string of a python dictionary to JSON object? json.loads() gives me a double quote error every time

问题

  1. {
  2. "intent": "catalog_search",
  3. "id": 1,
  4. "dependency": [],
  5. "args": {
  6. "text": "Could you please retrieve all table assets scanned before 1 hour?"
  7. }
  8. }

当我对其应用json.loads()时,我收到错误信息:"json.decoder.JSONDecodeError: 期望属性名用双引号括起来:第1行第2列(字符1)"。是什么原因?所有的键明显都有双引号,是我的格式有问题吗?

我以为问题可能是开头和结尾的双大括号,但当我移除它们时,我得到了相同的结果。

英文:

I have this as a string:

  1. {{
  2. "intent": "catalog_search",
  3. "id": 1,
  4. "dependency": [],
  5. "args": {{
  6. "text": "Could you please retrieve all table assets scanned before 1 hour?"
  7. }}
  8. }}

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

所有双括号都需要更改为单括号。这是有效的:

  1. {
  2. "intent": "catalog_search",
  3. "id": 1,
  4. "dependency": [],
  5. "args": {
  6. "text": "Could you please retrieve all table assets scanned before 1 hour?"
  7. }
  8. }
英文:

All the double braces need to be changed to single braces. This is valid:

  1. {
  2. "intent": "catalog_search",
  3. "id": 1,
  4. "dependency": [],
  5. "args": {
  6. "text": "Could you please retrieve all table assets scanned before 1 hour?"
  7. }
  8. }

huangapple
  • 本文由 发表于 2023年6月16日 05:03:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76485494.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定