davej Posted December 29, 2013 Share Posted December 29, 2013 What the heck is the "reviver" and why or when do I need it? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse Link to comment Share on other sites More sharing options...
Ingolme Posted December 29, 2013 Share Posted December 29, 2013 It seems like a transformation to the object that's done after the object is parsed. A function is called for every single element in the object that's being created and the return value of that function is the value that is used for the element in the resulting object. The function has two arguments: One referring to the key and one referring to the value of the element. I'm not sure why you would use this, but perhaps the program creating the JSON string works differently than the one parsing it and changes need to be made. Link to comment Share on other sites More sharing options...
davej Posted December 30, 2013 Author Share Posted December 30, 2013 Until weird things like that can be explained in a way that I can understand, I'll stick with using strings. Link to comment Share on other sites More sharing options...
thescientist Posted December 31, 2013 Share Posted December 31, 2013 (edited) I would still rather use JSON. I don't think I've ever hard parsing issues going back and forth between clients and servers, so a feature like that has never been an issue / of use. Edited December 31, 2013 by thescientist Link to comment Share on other sites More sharing options...
davej Posted December 31, 2013 Author Share Posted December 31, 2013 (edited) So neither of you guys use or worry about the reviver thing? I admit that it almost certainly has nothing to do with the simple data collections I will be using. Edited January 4, 2014 by davej Link to comment Share on other sites More sharing options...
justsomeguy Posted January 6, 2014 Share Posted January 6, 2014 It's just a shortcut to running a conversion function like that after the parsing. Someone decided it would be a good idea to be able to run the conversion function at the same time rather than parse the data structure first, then convert the data if you need to convert it. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now