源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

JS循环遍历JSON数据的方法

  • 时间:2022-09-07 16:06 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:JS循环遍历JSON数据的方法
JSON数据如:{"options":"[{/"text/":/"王家湾/",/"value/":/"9/"},{/"text/":/"李家湾/",/"valu e/":/"10/"},{/"text/":/"邵家湾/",/"value/":/"13/"}]"} 用js可以写成:
var data=[{name:"a",age:12},{name:"b",age:11},{name:"c",age:13},{name:"d",age:14}]; 
for(var o in data){ 
alert(o); 
alert(data[o]); 
alert("text:"+data[o].name+" value:"+data[o].age ); 
}
或是
<script type="text/javascript"> 
function text(){ 
var json = {"options":"[{/"text/":/"王家湾/",/"value/":/"9/"},{/"text/":/"李家湾/",/"value/":/"10/"},{/"text/":/"邵家湾/",/"value/":/"13/"}]"} 
json = eval(json.options) 
for(var i=0; i<json.length; i++) 
{ 
alert(json[i].text+" " + json[i].value) 
} 
} 
</script>
[b]PS:关于json操作,这里再为大家推荐几款比较实用的json在线工具供大家参考使用:[/b] 在线JSON代码检验、检验、美化、格式化工具: [url=http://tools.jb51.net/code/json]http://tools.jb51.net/code/json[/url] JSON在线格式化工具: [url=http://tools.jb51.net/code/jsonformat]http://tools.jb51.net/code/jsonformat[/url] 在线XML/JSON互相转换工具: [url=http://tools.jb51.net/code/xmljson]http://tools.jb51.net/code/xmljson[/url] json代码在线格式化/美化/压缩/编辑/转换工具: [url=http://tools.jb51.net/code/jsoncodeformat]http://tools.jb51.net/code/jsoncodeformat[/url] 在线json压缩/转义工具: [url=http://tools.jb51.net/code/json_yasuo_trans]http://tools.jb51.net/code/json_yasuo_trans[/url] C语言风格/HTML/CSS/json代码格式化美化工具: [url=http://tools.jb51.net/code/ccode_html_css_json]http://tools.jb51.net/code/ccode_html_css_json[/url]
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部