JSON.stringify does not stringify functions:
Example
const person = {
name: "John",
age: function () {return 30;}
};
let myString = JSON.stringify(person);
document.getElementById("demo"). innerHTML = myString;
This can be "fixed" if the function is converted to a string before stringification.
This can be "fixed" if you convert the functions into strings before stringifying.
Example
const person = {
name: "John",
age: function () {return 30;}
};
person.age = person.age.toString();
let myString = JSON.stringify(person);
document.getElementById("demo"). innerHTML = myString;
The above is the detailed content of How to implement Java function stringification. For more information, please follow other related articles on the PHP Chinese website!