Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
0912109f
Commit
0912109f
authored
Jan 23, 2010
by
jeresig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose the JSON parsing logic. Fixes #5914.
parent
a6ef036b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
17 deletions
+23
-17
ajax.js
src/ajax.js
+1
-17
core.js
src/core.js
+22
-0
No files found.
src/ajax.js
View file @
0912109f
...
@@ -591,23 +591,7 @@ jQuery.extend({
...
@@ -591,23 +591,7 @@ jQuery.extend({
if
(
typeof
data
===
"string"
)
{
if
(
typeof
data
===
"string"
)
{
// Get the JavaScript object, if JSON is used.
// Get the JavaScript object, if JSON is used.
if
(
type
===
"json"
||
!
type
&&
ct
.
indexOf
(
"json"
)
>=
0
)
{
if
(
type
===
"json"
||
!
type
&&
ct
.
indexOf
(
"json"
)
>=
0
)
{
// Make sure the incoming data is actual JSON
data
=
jQuery
.
parseJSON
(
data
);
// Logic borrowed from http://json.org/json2.js
if
(
/^
[\]
,:{}
\s]
*$/
.
test
(
data
.
replace
(
/
\\(?:[
"
\\\/
bfnrt
]
|u
[
0-9a-fA-F
]{4})
/g
,
"@"
)
.
replace
(
/"
[^
"
\\\n\r]
*"|true|false|null|-
?\d
+
(?:\.\d
*
)?(?:[
eE
][
+
\-]?\d
+
)?
/g
,
"]"
)
.
replace
(
/
(?:
^|:|,
)(?:\s
*
\[)
+/g
,
""
)))
{
// Try to use the native JSON parser first
if
(
window
.
JSON
&&
window
.
JSON
.
parse
)
{
data
=
window
.
JSON
.
parse
(
data
);
}
else
{
data
=
(
new
Function
(
"return "
+
data
))();
}
}
else
{
jQuery
.
error
(
"Invalid JSON: "
+
data
);
}
// If the type is "script", eval it in global context
// If the type is "script", eval it in global context
}
else
if
(
type
===
"script"
||
!
type
&&
ct
.
indexOf
(
"javascript"
)
>=
0
)
{
}
else
if
(
type
===
"script"
||
!
type
&&
ct
.
indexOf
(
"javascript"
)
>=
0
)
{
...
...
src/core.js
View file @
0912109f
...
@@ -470,6 +470,28 @@ jQuery.extend({
...
@@ -470,6 +470,28 @@ jQuery.extend({
error
:
function
(
msg
)
{
error
:
function
(
msg
)
{
throw
msg
;
throw
msg
;
},
},
parseJSON
:
function
(
data
)
{
// Make sure the incoming data is actual JSON
// Logic borrowed from http://json.org/json2.js
if
(
/^
[\]
,:{}
\s]
*$/
.
test
(
data
.
replace
(
/
\\(?:[
"
\\\/
bfnrt
]
|u
[
0-9a-fA-F
]{4})
/g
,
"@"
)
.
replace
(
/"
[^
"
\\\n\r]
*"|true|false|null|-
?\d
+
(?:\.\d
*
)?(?:[
eE
][
+
\-]?\d
+
)?
/g
,
"]"
)
.
replace
(
/
(?:
^|:|,
)(?:\s
*
\[)
+/g
,
""
)))
{
// Try to use the native JSON parser first
if
(
window
.
JSON
&&
window
.
JSON
.
parse
)
{
data
=
window
.
JSON
.
parse
(
data
);
}
else
{
data
=
(
new
Function
(
"return "
+
data
))();
}
}
else
{
jQuery
.
error
(
"Invalid JSON: "
+
data
);
}
return
data
;
},
noop
:
function
()
{},
noop
:
function
()
{},
...
...
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