Side navigation
#5865 closed enhancement (wontfix)
Opened January 19, 2010 11:34AM UTC
Closed November 01, 2010 05:33AM UTC
Last modified March 14, 2012 12:54AM UTC
Allow User To Specify A Reviver Function For Parsing JSON In AJAX Requests
Reported by: | MrKWatkins | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | 1.4.1 |
Component: | ajax | Version: | 1.4 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
The native JSON.parse method allows an optional reviver function to be specified; this allows you to do things such as convert strings into Date objects. It would be nice if jQuery allowed the user to specify a reviver function to use with the JSON parsing done inside the httpData function. To use a reviver currently you have to process the data as text and handled the JSON parsing yourself.
Attachments (0)
Change History (2)
Changed January 20, 2010 02:41AM UTC by comment:1
Changed November 01, 2010 05:33AM UTC by comment:2
resolution: | → wontfix |
---|---|
status: | new → closed |
json2.js manages to allow the use of a reviver, but I think the fact of the matter is that very few people actually care about this, and those that do can duck punch $.parseJSON to add support for it.
It's a little bit tricky. jQuery only can use a native JSON parser if one exists. If there isn't one, it evaluates the code using "new Function" which wouldn't be able to use the reviver. That could cause some bugs because the developer would expect the reviver to be used in all cases. So if you are depending upon a JSON implementation that can take a reviver it's safest to ask for text and parse it yourself.