In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the unusual uses of JSON stringify ()". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what are the unusual uses of JSON stringify ().
JSON.stringify () serializes only traverable properties (enumerable=true)
Copy the code
Varobj= {}
Object.defineProperties (obj, {
'foo': {
Value:1
Enumerable:true
}
'bar': {
Value:2
Enumerable:false
}
})
JSON.stringify (obj); / / "{" foo ": 1}"
Copy the code
JSON.stringify (obj,fn | arr)
1) when the second parameter is an array, it represents the list of attributes of the object that needs to be serialized
2) when the second parameter is a method, function (key,value) {} represents the key-value value corresponding to each attribute, and the final return value can be used to change the original result.
This method can be used to change the contents of an object before serialization.
Copy the code
Varo= {a: {b:1}}
Functionf (key,value) {
Console.log ("[" + key+ "]:" + value)
Returnvalue
}
JSON.stringify (ofline f)
/ / []: [objectObject]
/ / [a]: [objectObject]
/ / [b]: 1
/ /'{"a": {"b": 1}}'
/ / Recursive processing, the last returned result is processed each time
Copy the code
JSON.stringify (obj,null,number | string)
You can accept the third parameter, which can be used to print objects in format
When the third parameter is a numeric value, it represents the number of spaces before each attribute
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.