This article describes the implementation method of JS object and json string format conversion, and is shared with you for your reference. The specific implementation method is as follows:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript">
var obj = new Object();
= "Bajie"
= 500;
//Define objects through literal form
var obj1 = { "Name": "Bajie", "Age": "500" };
var arr = [{ "Name": "Bajie", "Age": "500" }, { "Name": "Bajie1", "Age": "1000" }];
//JSON format: Use the literal representation of json as a string, then it is a json format string
var str = '{ "Name": "Bajie", "Age": "500" }';
var jsonstrarr = '[{ "Name": "Bajie", "Age": "500" }, { "Name": "Bajie1", "Age": "1000" }];';
//Convert json string to js object (array)
var resobj = (str);
alert();
</script>
</head>
<body>
</body>
</html>
Transfer between js and json objects in front-end:
1. Convert JS object to JSON
Processing: Refer to a file and call the() method. For example:
var json_data = (data);
PS: This file can be downloaded by searching online.
2. Convert JSON to JS
1. Processing: Use a method $.parseJSON() in jQuery to convert JSON format data into JS objects. For example:
var data = $.parseJSON(json_data);
2. Method to convert json into js object:
Through the above expression, the Json format string responding to the client on the server is parsed into a Json (format) object with the name "json", and data access can be performed through "json." or "json[]".
Transferring js objects and json objects in the background:
.NET Framework 4 is in. Serialize and deserialize data using JavaScriptSerializer class
Example:
List<ApplyPart> _ApplyPart = new JavaScriptSerializer().Deserialize<List<ApplyPart>>(param);
PS: Regarding json operation, here are some more practical json online tools for your reference:
Online JSON code verification, inspection, beautification and formatting tools:
http://tools./code/json
JSON online formatting tool:
http://tools./code/jsonformat
Online XML/JSON mutual conversion tool:
http://tools./code/xmljson
json code online formatting/beautification/compression/editing/converting tools:
http://tools./code/jsoncodeformat
Online json compression/escaping tools:
http://tools./code/json_yasuo_trans
C language style/HTML/CSS/json code formatting and beautification tools:
http://tools./code/ccode_html_css_json
I hope this article will be helpful to everyone's web programming.