Home > Web Front-end > JS Tutorial > Very easy to use JsonToString method simple example_javascript skills

Very easy to use JsonToString method simple example_javascript skills

WBOY
Release: 2016-05-16 17:28:31
Original
1555 people have browsed it

Very easy to use JsonToString method
Jsontostring code

Copy code The code is as follows:

function JsonToString(o) {
var arr = [];
var fmt = function(s) {
if (typeof s == 'object' && s != null) return JsonToStr(s );
        return /^(string|number)$/.test(typeof s) ? "'" s "'" : s; .push("'" i "':" fmt(o[i]));
return '{' arr.join(',') '}';
}



I feel great using it anyway, haha
Also: If you don’t want the numbers in json to be stringified. You can modify it:

return /^(string|number)$/.test(typeof s) ? '"' s '"' : s; is: return /^(string)$/.test(typeof s) ? '"' s '"' : s; (actually just ignore the number type)
Related labels:
source:php.cn
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