In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Json format string serialization and deserialization of what is the advanced use, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can get something.
(1) only serialize the value corresponding to the specified attribute into a string:
Var filter = {name: 'Jerry', sex:' male', age: '10'}; var jsonStr4 = JSON.stringify (filter, [' name']); console.log (jsonStr4)
The name of the parameter you want to participate in the serialization is passed in through the second parameter of the JSON.stringify method.
In the above example, only the name field and its corresponding values participate in the serialization, and the output is as follows:
(2) when serializing, you can also write functions to implement custom serialization logic:
Var obj = {name: 'Jerry', sex:' male', age: '40'}; var jsonStr5 = JSON.stringify (obj, function (key, value) {if (key =' name') {return'my name is:'+ value;} else if (key = 'sex') {/ do not return, discard this attribute} else return value;})
Output:
The value of the name attribute is implemented through a custom function prefixed with a prefix. The sex property is discarded and the age property remains unchanged.
(3) add indentation when serializing to make the output string easier to read.
Var obj6 = {name: 'Jerry', sex:' male', age: '40'}; var jsonStr6 = JSON.stringify (obj6, null, 5); console.log (jsonStr6)
Output:
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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: 219
*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.