欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Jquery通過JSON字符串創(chuàng)建JSON對象

 更新時間:2014年08月24日 09:56:56   投稿:whsnow  
這篇文章主要介紹了Jquery如何通過JSON字符串創(chuàng)建JSON對象,并附詳細示例,需要的朋友可以參考下
<html>
<body>
<h2>通過 JSON 字符串來創(chuàng)建對象</h3>
<p>
First Name: <span id="fname"></span><br /> 
Last Name: <span id="lname"></span><br /> 
</p> 
<script type="text/javascript">
//txt為字符串
var txt = '{"employees":[' +
'{"firstName":"Bill","lastName":"Gates" },' +
'{"firstName":"George","lastName":"Bush" },' +
'{"firstName":"Thomas","lastName":"Carter" }]}';
//通過eval()方法
//var obj = eval ("(" + txt + ")"); 
//通過JSON解析
//obj = jQuery.parseJSON(txt);
obj = JSON.parse(txt);

document.getElementById("fname").innerHTML=obj.employees[1].firstName 
document.getElementById("lname").innerHTML=obj.employees[1].lastName 
</script>
</body>
</html>

PS:關(guān)于json操作,這里再為大家推薦幾款比較實用的json在線工具供大家參考使用:

在線JSON代碼檢驗、檢驗、美化、格式化工具:
http://tools.jb51.net/code/json

JSON在線格式化工具:
http://tools.jb51.net/code/jsonformat

在線XML/JSON互相轉(zhuǎn)換工具:
http://tools.jb51.net/code/xmljson

json代碼在線格式化/美化/壓縮/編輯/轉(zhuǎn)換工具:
http://tools.jb51.net/code/jsoncodeformat

在線json壓縮/轉(zhuǎn)義工具:

http://tools.jb51.net/code/json_yasuo_trans

C語言風格/HTML/CSS/json代碼格式化美化工具:
http://tools.jb51.net/code/ccode_html_css_json

相關(guān)文章

最新評論