object_-_json
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| object_-_json [2015/06/19 12:26] – created 86.73.246.173 | object_-_json [2015/08/04 18:13] (current) – 78.250.193.162 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | Il est possible d' | ||
| + | |||
| + | ===Notes=== | ||
| + | Pour pouvoir faire l' | ||
| + | |||
| + | Par exemple, imaginons un programme qui ouvre un .json contenant la serialisation json d'un objet < | ||
| + | |||
| + | == objet -> json -> file :== | ||
| < | < | ||
| import jsonpickle | import jsonpickle | ||
| Line 29: | Line 37: | ||
| print o_json | print o_json | ||
| print(o2.myFirstProperty) | print(o2.myFirstProperty) | ||
| - | print(o2.mySecondProperty)</ | + | print(o2.mySecondProperty) |
| + | |||
| + | f = open(" | ||
| + | f.write(o_json) | ||
| + | f.close()</ | ||
| + | |||
| + | == file -> json -> objet :== | ||
| + | < | ||
| + | import jsonpickle | ||
| + | |||
| + | class myObject(object): | ||
| + | """ | ||
| + | myFirstProperty = None | ||
| + | mySecondProperty = None | ||
| + | |||
| + | class myObjectInterface(object): | ||
| + | """ | ||
| + | def __init__(self, | ||
| + | self.target = target | ||
| + | |||
| + | def updateMyFirstProperty(self, | ||
| + | self.target.myFirstProperty = newValue | ||
| + | |||
| + | def updateMySecondProperty(self, | ||
| + | self.target.mySecondProperty = newValue | ||
| + | |||
| + | f = open(" | ||
| + | o_json = f.read() | ||
| + | f.close() | ||
| + | o = jsonpickle.decode(o_json) | ||
| + | |||
| + | print o_json | ||
| + | print o | ||
| + | print(o.myFirstProperty) | ||
| + | print(o.mySecondProperty)</ | ||
object_-_json.1434709580.txt.gz · Last modified: 2015/06/19 12:26 by 86.73.246.173