> Modules standards > Modules pour internet > Utilisation de JSON
Utilisation de JSON
Pour utiliser le package, faire import json
Décodage de json :
- x = '["a", {"c": [2, 3.5], "b": 1}, ["e", "f"], true, null]'; y = json.loads(x) met dans y l'objet python correspondant : [u'a', {u'c': [2, 3.5], u'b': 1}, [u'e', u'f'], True, None]
- y = json.load(fh) : on peut charger directement un objet json d'un filehandle de fichier (attention, pas la même fonction !)
Copyright python-simple.com
programmer en python, tutoriel python, graphes en python, Aymeric Duclert