【问题标题】:How to decode JSON special characters in string in python?如何在python中解码字符串中的JSON特殊字符?
【发布时间】:2021-03-18 16:41:45
【问题描述】:

这是我的代码:

import requests
import json

r = requests.get(url="news_api_here")
json_data = json.loads(r.content)

for i in range(len(json_data)):
    title = str(json_data[i]["headline"])
    print(title)

给定标题的输出是这样的:

Development%2c Expansion%2c Merger%2c Acquisition%2c New Product Launches%2c and Pricing Analysis%3c%2fa%3e%3c

如何将字符串解码为正确的字符?

【问题讨论】:

标签: python json


【解决方案1】:

使用请求的库unquote()

import requests

requests.utils.unquote(title)

【讨论】:

    猜你喜欢
    • 2016-10-07
    • 1970-01-01
    • 2013-09-08
    • 2011-09-18
    • 2016-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多