Home > Java > javaTutorial > body text

How to implement Java function stringification

WBOY
Release: 2023-05-04 23:13:05
forward
1310 people have browsed it

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!