mirror of
https://github.com/python/cpython.git
synced 2025-09-09 10:21:43 +00:00
Fix json examples so they would actually work in Py3k
This commit is contained in:
parent
fc02aef099
commit
2505bc6c94
1 changed files with 8 additions and 8 deletions
|
@ -19,13 +19,13 @@ Encoding basic Python object hierarchies::
|
|||
'["foo", {"bar": ["baz", null, 1.0, 2]}]'
|
||||
>>> print(json.dumps("\"foo\bar"))
|
||||
"\"foo\bar"
|
||||
>>> print(json.dumps(u'\u1234'))
|
||||
>>> print(json.dumps('\u1234'))
|
||||
"\u1234"
|
||||
>>> print(json.dumps('\\'))
|
||||
"\\"
|
||||
>>> print(json.dumps({"c": 0, "b": 0, "a": 0}, sort_keys=True))
|
||||
{"a": 0, "b": 0, "c": 0}
|
||||
>>> from StringIO import StringIO
|
||||
>>> from io import StringIO
|
||||
>>> io = StringIO()
|
||||
>>> json.dump(['streaming API'], io)
|
||||
>>> io.getvalue()
|
||||
|
@ -50,13 +50,13 @@ Decoding JSON::
|
|||
|
||||
>>> import json
|
||||
>>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
|
||||
[u'foo', {u'bar': [u'baz', None, 1.0, 2]}]
|
||||
['foo', {'bar': ['baz', None, 1.0, 2]}]
|
||||
>>> json.loads('"\\"foo\\bar"')
|
||||
u'"foo\x08ar'
|
||||
>>> from StringIO import StringIO
|
||||
'"foo\x08ar'
|
||||
>>> from io import StringIO
|
||||
>>> io = StringIO('["streaming API"]')
|
||||
>>> json.load(io)
|
||||
[u'streaming API']
|
||||
['streaming API']
|
||||
|
||||
Specializing JSON object decoding::
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue