'str' object has no attribute 'json'
时间: 2023-09-21 09:03:17 浏览: 258
This error message usually appears when you try to use the `.json()` method on a string object. The `.json()` method is used to convert a JSON string to a Python dictionary or list, but it can only be used on objects that are of type `response` from the `requests` library or a similar library.
To fix this error, you should make sure that the object you are trying to convert to JSON is a `response` object, rather than a string. If you are using the `requests` library to make API calls, make sure to use the `.json()` method on the response object, not on the string representation of the response.
For example, instead of doing:
```
response = requests.get(url)
json_string = response.text
data = json_string.json()
```
Do:
```
response = requests.get(url)
data = response.json()
```
阅读全文