Example of mutual conversion between JSON objects and JSON strings in javascript, javascriptjson
This document describes how to convert JSON objects and JSON strings in javascript. Share it with you for your reference. The details are as follows:
<Script type = "text/javascript"> // obtain the property value var jsonObj = {name: "jxqlovejava"} Based on the property name of the JSON object; // console of the json object. log (jsonObj. name); // "jxqlovejava" var jsonStr = '{name: "jxqlovejava "}'; // JSON string to JSON object method 1 var jsonObj2 = eval ("(" + jsonStr + ")"); console. log (jsonObj2.name); // jxqlovejava // JSON string to JSON object method 2 var jsonObj3 = JSON. parse (jsonStr); console. log (jsonObj3.name); // jxqlovejava // JSON object to the JSON String jsonStr2 = JSON. stringify (jsonObj); console. log (jsonStr2); // {name: "jxqlovejava"} </script>
I hope this article will help you design javascript programs.