I am trying to count the number of Unicode characters in the JSON data. I am using requests to get the data from the feed.
import requests
r = requests.get('https://venmo.com/api/v5/public?since=1438578858&until=1438578958')'
j_data = r.text
Now, I need to convert the j_data
into a dictionary to get the message
items alone. If I just use json.loads(j_data)
, I get UnicodeEncodeError: 'charmap' codec can't encode character
.
Therefore, I am encoding the j_data
and then trying to convert to dict using loads
. I am getting this error
TypeError: the JSON object must be str, not 'bytes'
How to approach this problem?
Code:
import requests
import json
r = requests.get('https://venmo.com/api/v5/public?since=1438578858&until=1438578958')
j_data = r.text
encoded = j_data.encode()
b = json.loads(encoded)
print(b)