javascript - JSON stringify objects excluding methods -
I am working on a Firefox extension and I am trying to strip a JSON object.
I am using it, but I am getting this error:
I really care only about the first level or the two or the properties inside the object, and I do not care about the ways / functions if I do not have to do all this, then what to do to disturb an object An easy way? Here's a bit of code I'm using: The console window has this error: It is that I can copy from the firebug console window: Here is a screenshot of the object: You can define a custom function on your object which is called For example: Edit: If you have all non-impact values, you can try to do something like this: You will probably end up with some attributes set on Javascript logic "NS_ERROR_XPC_BAD_CONVERT_JS" could not be changed
var s = JSONstring ('ABC'); Try Firebug.Console.log (gContextMenu); S = JSON.stringify (gContextMenu); Firebug.Console.log (s); } Hold (e) {Firebug.Console.log ('error'); Firebug.Console.log (E); } Var s = JSONstring.make ('abc'); Firebug.Console.log (s); Firebug.Console.log (gContextMenu);
toJSON () which gives only the element of the object that you want to a certain extent counter-intuitive, your
Return a JSON string do not toJSON function It should - it should be used only as input represents an object that
JSON.stringify .
// You want to have an object with some attributes and some you do not do var o = {a: "value1", b : "Value2", doCalc: function () {return.a + "" + this.b}}; // to define a custom JSON () method o.toJSON = function () {return {a: this.a, calc: this.doCalc ()}}; JSON.stringify (o); In your case, you should be able to define this method for
gContextMenu, "//" {"a": "value", "calc": "value1 value2"} '
JSON.stringify , it clearly defines what you want and do not want to do, but I do not think it There is a better way.
o.toJSON = function () {Var attrs = {}; For (var attr) {if (this typeof [attr]! = "Function") {attrs [attr] = string (this [attr]); // string to string}} return attrs; };
"[object object]" , but if you want everything to be inspected, then it may be possible One is not the issue. You can also check for this
Comments
Post a Comment