Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
855d63c2
Commit
855d63c2
authored
Apr 13, 2011
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#9233: Fix json.loads({}) to return a dict (instead of a list), when _json is not available.
parent
7e721b0c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
0 deletions
+11
-0
Lib/json/decoder.py
Lib/json/decoder.py
+6
-0
Lib/json/tests/test_decode.py
Lib/json/tests/test_decode.py
+5
-0
No files found.
Lib/json/decoder.py
View file @
855d63c2
...
@@ -161,6 +161,12 @@ def JSONObject(s_and_end, strict, scan_once, object_hook, object_pairs_hook,
...
@@ -161,6 +161,12 @@ def JSONObject(s_and_end, strict, scan_once, object_hook, object_pairs_hook,
nextchar
=
s
[
end
:
end
+
1
]
nextchar
=
s
[
end
:
end
+
1
]
# Trivial empty object
# Trivial empty object
if
nextchar
==
'}'
:
if
nextchar
==
'}'
:
if
object_pairs_hook
is
not
None
:
result
=
object_pairs_hook
(
pairs
)
return
result
,
end
pairs
=
{}
if
object_hook
is
not
None
:
pairs
=
object_hook
(
pairs
)
return
pairs
,
end
+
1
return
pairs
,
end
+
1
elif
nextchar
!=
'"'
:
elif
nextchar
!=
'"'
:
raise
ValueError
(
errmsg
(
"Expecting property name"
,
s
,
end
))
raise
ValueError
(
errmsg
(
"Expecting property name"
,
s
,
end
))
...
...
Lib/json/tests/test_decode.py
View file @
855d63c2
...
@@ -16,6 +16,11 @@ class TestDecode(TestCase):
...
@@ -16,6 +16,11 @@ class TestDecode(TestCase):
self
.
assertTrue
(
isinstance
(
rval
,
float
))
self
.
assertTrue
(
isinstance
(
rval
,
float
))
self
.
assertEqual
(
rval
,
1.0
)
self
.
assertEqual
(
rval
,
1.0
)
def
test_empty_objects
(
self
):
self
.
assertEqual
(
json
.
loads
(
'{}'
),
{})
self
.
assertEqual
(
json
.
loads
(
'[]'
),
[])
self
.
assertEqual
(
json
.
loads
(
'""'
),
""
)
def
test_object_pairs_hook
(
self
):
def
test_object_pairs_hook
(
self
):
s
=
'{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}'
s
=
'{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}'
p
=
[(
"xkd"
,
1
),
(
"kcw"
,
2
),
(
"art"
,
3
),
(
"hxm"
,
4
),
p
=
[(
"xkd"
,
1
),
(
"kcw"
,
2
),
(
"art"
,
3
),
(
"hxm"
,
4
),
...
...
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