【问题标题】:How to deal with escape characters with JSON loads?如何处理带有 JSON 负载的转义字符?
【发布时间】:2023-02-09 07:18:45
【问题描述】:
search = """
[{"text":"Dolores Keane - \"Craigie Hills\" (1982)"}]
"""
print(loads(search)) # Returns Error
print(search.replace('"',"'")) # Turns all double quotes to single quotes, both the escaped and non escaped ones

这是我的问题:我只是不知道如何将这种字符串加载到 JSON 中。有小费吗?我尝试了十亿件事。尝试过 repr(search) 等,但没有任何效果。

错误: json.decoder.JSONDecodeError: Expecting ',' 分隔符:第 2 行第 28 列(字符 28)

【问题讨论】:

    标签: python json escaping


    【解决方案1】:

    您需要使用双反斜杠来转义 json:

    search = """
    [{"text":"Dolores Keane - \"Craigie Hills\" (1982)"}]
    """
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-07
      • 1970-01-01
      • 2021-11-14
      • 2013-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多