联系我们
简单又实用的WordPress网站制作教学
当前位置:网站首页 > 网页前端技术 > 正文

Jquery通过JSON字符串创建JSON对象 - Web前端

作者:98wpeu发布时间:2026-07-12分类:网页前端技术浏览:2


导读:<html><body><h2>通过json字符串来创建对象</h3><p>FirstName:<...
<html>
<body>
<h2>通过 json 字符串来创建对象</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:关于json操作,这里再为大家推荐几款比较实用的json在线工具供大家参考使用:

在线JSON代码检验、检验、美化、格式化工具:
http://tools.jb51.net/code/json

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

在线xml/JSON互相转换工具:
http://tools.jb51.net/code/xmljson

json代码在线格式化/美化/压缩/编辑/转换工具:
http://tools.jb51.net/code/jsoncodeformat

在线json压缩/转义工具:

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

C语言风格/HTML/CSS/json代码格式化美化工具:
http://tools.jb51.net/code/ccode_html_css_json

标签:字符串对象WebJSONJquery


网页前端技术排行
最近发表
网站分类
标签列表