#5865 closed enhancement (wontfix)
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.
Change History (2)
comment:1 Changed 14 years ago by
comment:2 Changed 13 years ago by
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.
Note: See
TracTickets for help on using
tickets.
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.