[Python] simplest way to read standard JSON with UTF8 Latin Letters

Discussão em 'Python' iniciado por Stack, Maio 23, 2025.

  1. Stack

    Stack Membro Participativo

    My server only offers Python v2.7.5.

    This script is working:

    import json

    with open('Ranger_Policies.json', 'r') as f:
    data = json.loads(f.read())
    for p in data['policies']:
    print "Service:", p['service'] #, "Name:", p['name']


    When I remove the comment-mark, the p['name'] triggs an error:


    UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 29: ordinal not in range(128)
    ​

    How to correct this specific source code, it must work with any standard UTF8 for Latin.

    Continue reading...

Compartilhe esta Página