Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
2505bc6c
Kaydet (Commit)
2505bc6c
authored
May 15, 2008
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix json examples so they would actually work in Py3k
üst
fc02aef0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
8 deletions
+8
-8
json.rst
Doc/library/json.rst
+8
-8
No files found.
Doc/library/json.rst
Dosyayı görüntüle @
2505bc6c
...
@@ -19,13 +19,13 @@ Encoding basic Python object hierarchies::
...
@@ -19,13 +19,13 @@ Encoding basic Python object hierarchies::
'["foo", {"bar": ["baz", null, 1.0, 2]}]'
'["foo", {"bar": ["baz", null, 1.0, 2]}]'
>>> print(json.dumps("\"foo\bar"))
>>> print(json.dumps("\"foo\bar"))
"\"foo\bar"
"\"foo\bar"
>>> print(json.dumps(
u
'\u1234'))
>>> print(json.dumps('\u1234'))
"\u1234"
"\u1234"
>>> print(json.dumps('\\'))
>>> print(json.dumps('\\'))
"\\"
"\\"
>>> print(json.dumps({"c": 0, "b": 0, "a": 0}, sort_keys=True))
>>> print(json.dumps({"c": 0, "b": 0, "a": 0}, sort_keys=True))
{"a": 0, "b": 0, "c": 0}
{"a": 0, "b": 0, "c": 0}
>>> from
StringIO
import StringIO
>>> from
io
import StringIO
>>> io = StringIO()
>>> io = StringIO()
>>> json.dump(['streaming API'], io)
>>> json.dump(['streaming API'], io)
>>> io.getvalue()
>>> io.getvalue()
...
@@ -50,13 +50,13 @@ Decoding JSON::
...
@@ -50,13 +50,13 @@ Decoding JSON::
>>> import json
>>> import json
>>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
>>> 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"')
>>> json.loads('"\\"foo\\bar"')
u
'"foo\x08ar'
'"foo\x08ar'
>>> from
StringIO
import StringIO
>>> from
io
import StringIO
>>> io = StringIO('["streaming API"]')
>>> io = StringIO('["streaming API"]')
>>> json.load(io)
>>> json.load(io)
[
u
'streaming API']
['streaming API']
Specializing JSON object decoding::
Specializing JSON object decoding::
...
@@ -65,7 +65,7 @@ Specializing JSON object decoding::
...
@@ -65,7 +65,7 @@ Specializing JSON object decoding::
... if '__complex__' in dct:
... if '__complex__' in dct:
... return complex(dct['real'], dct['imag'])
... return complex(dct['real'], dct['imag'])
... return dct
... return dct
...
...
>>> json.loads('{"__complex__": true, "real": 1, "imag": 2}',
>>> json.loads('{"__complex__": true, "real": 1, "imag": 2}',
... object_hook=as_complex)
... object_hook=as_complex)
(1+2j)
(1+2j)
...
@@ -81,7 +81,7 @@ Extending :class:`JSONEncoder`::
...
@@ -81,7 +81,7 @@ Extending :class:`JSONEncoder`::
... if isinstance(obj, complex):
... if isinstance(obj, complex):
... return [obj.real, obj.imag]
... return [obj.real, obj.imag]
... return json.JSONEncoder.default(self, obj)
... return json.JSONEncoder.default(self, obj)
...
...
>>> dumps(2 + 1j, cls=ComplexEncoder)
>>> dumps(2 + 1j, cls=ComplexEncoder)
'[2.0, 1.0]'
'[2.0, 1.0]'
>>> ComplexEncoder().encode(2 + 1j)
>>> ComplexEncoder().encode(2 + 1j)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment