Search code examples
pythonjsonresponse

How to parse python b' before dict


How to access id or nickname value with python3:

response._content = b'{"id":44564,"nickname":'Demo'}

Solution

  • It looks like you're trying to read in a Json string and convert it to a dict, e.g.:

    import json
    
    # response._content = b'{"id":44564,"nickname":"Demo"}'
    
    data = json.loads(response._content.decode('utf-8'))
    
    # data = {'id': 44564, 'nickname': 'Demo'}