In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about how to use JSON.stringify () and JSON.parse () in JavaScript. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
@ track weekplanList = []; / / [] represents the collective {} represents the object / / displays the contents of the weekly plan to the home page showPlanContentToIndex () {this.showSpinnerEvent () / / display the progress bar this.callServer (GetWeekPlanAction, / / get the selection type, specific content-query method function (response) {/ / response is GetWeekPlanAction () return value as formal parameter let values = JSON.parse (JSON.stringify (response)); / / JSON.stringify () method is used to convert JavaScript value to JSON string. / / JSON.parse () JSON is usually used to exchange data with the server. / / it is usually a string when receiving server data. We can use the JSON.parse () method to convert the data into JavaScript objects. This.weekplanList = values; / / convert the English displayed at the front desk into Chinese values.forEach ((item) = > {if (item.Form_Type_MDT_AP_CHN__c = 'Customer Visit') {item.Form_Type_MDT_AP_CHN__c =' customer visit' } else if (item.Form_Type_MDT_AP_CHN__c = = 'Regional Support') {item.Form_Type_MDT_AP_CHN__c =' regional platform / support';} else if (item.Form_Type_MDT_AP_CHN__c = = 'Market Access') {item.Form_Type_MDT_AP_CHN__c =' market access' } else if (item.Form_Type_MDT_AP_CHN__c = = 'Dealer Cooperation') {item.Form_Type_MDT_AP_CHN__c =' Reseller Cooperation' } else if (item.Form_Type_MDT_AP_CHN__c = = 'Meeting') {item.Form_Type_MDT_AP_CHN__c =' academic events-internal meetings' } else if (item.Form_Type_MDT_AP_CHN__c = = 'Personnel Development') {item.Form_Type_MDT_AP_CHN__c =' personnel Development' } else if (item.Form_Type_MDT_AP_CHN__c = = 'Device Process') {item.Form_Type_MDT_AP_CHN__c =' device process' } else if (item.Form_Type_MDT_AP_CHN__c = = 'Project Debriefing') {item.Form_Type_MDT_AP_CHN__c =' Project Progress';}}); console.log ('this.weekplanList1',values); this.hiddenSpinnerEvent () }, {} / / GetWeekPlanAction () does not need to pass parameters, so the third parameter is empty);} let and var comparison
ES2015 (ES6) adds two important JavaScript keywords: let and const. Variables declared by let are valid only within the block of code where the let command is located. Const declares a read-only constant, and once declared, the value of the constant cannot be changed.
Variables declared with the var keyword do not have block-level scope and can still be accessed outside {}.
{var x = 2;} / / you can use the x variable here
The variables declared by let are only valid within the code block {} where the let command is located and cannot be accessed outside {}.
{let x = 2;} / / the x variable cannot be used here
Valid instance in the code block {} where the let command resides
Var x = 10 let / here the output x is 10 {let x = 2; / / here the output x is 2} / / here the output x is 101, JSON.stringify ()
Method is used to convert a JavaScript value to a JSON string.
Grammar
JSON.stringify (value [, replacer [, space]])
Parameter description:
Value:
Required, the JavaScript value to convert (usually an object or array).
Replacer:
Optional. The function or array used to convert the result.
If replacer is a function, JSON.stringify calls the function, passing in the key and value of each member. Use the return value instead of the original value. If this function returns undefined, members are excluded. The key of the root object is an empty string: ".
If replacer is an array, only members of the array that have key values are converted. The conversion order of members is the same as the order of keys in an array.
Space:
Optionally, the text adds indents, spaces, and newline characters, and if space is a number, the return value text indents a specified number of spaces at each level, and if space is greater than 10, the text is indented by 10 spaces. Space can also use non-numbers, such as:\ t.
Return value:
Returns a string containing JSON text.
2. JSON.parse ()
JSON is usually used to exchange data with the server.
It is usually a string when receiving server data.
We can use the JSON.parse () method to convert the data into JavaScript objects.
Grammar
JSON.parse (text [, reviver])
Parameter description:
* * text:** is required, a valid JSON string.
Reviver: optionally, a function that converts the result, which will be called for each member of the object.
3. Example: let jsonData = [{group: 1, id: 2, name: "aa"}, {group: 2, id: 1, name: "bb"}]; let jsonData1 = JSON.stringify (jsonData); console.log (jsonData1); console.log ("jsonData1 index 0 data = =" + jsonData1 [0]); console.log ("group attribute of jsonData1 index 0 = =" + jsonData1 [0] .group); let jsonData2 = JSON.parse (jsonData1); console.log (jsonData2) Console.log ("jsonData2 index 0 data = =" + jsonData2 [0]); console.log ("group attribute of jsonData2 index 0 = =" + jsonData2 [0] .group)
This is how JSON.stringify () and JSON.parse () are used in JavaScript shared by Xiaobian. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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.