javascript的代码:
<script> var JSONObject= { "name":"John Johnson", "street":"Oslo West 555", "age":33, "phone":"555 1234567"}; document.getElementById("jname").innerHTML=JSONObject.name document.getElementById("jage").innerHTML=JSONObject.age document.getElementById("jstreet").innerHTML=JSONObject.street document.getElementById("jphone").innerHTML=JSONObject.phone </script>html的代码:
<p> Name: <span id="jname"></span><br /> Age: <span id="jage"></span><br /> Address: <span id="jstreet"></span><br /> Phone: <span id="jphone"></span><br /> </p>字符串类型转给服务器,服务器发过来的再转成JavaScript对象
//将js对象用stringify转成字符串类型,发送给服务器 var send_data = JSON.stringify(JSONObject); // 服务器传递过来的字符串json数据, var get_js_obj = JSON.parse(send_data);