lxfp.net
当前位置:首页 >> js怎么遍历json的数组并输出到html中 >>

js怎么遍历json的数组并输出到html中

例如数据库里面的json字符串是这样的 ? 1 2 3 4 5 var str = '[{"name":"宗2瓜","num":"1","price":"122"},{"name":"宗呱呱","num":"1","price":"100"}]'; var xqo = eval('(' + str + ')'); for(var i in xqo){ alert(xqo[i].name); } 上面的是...

循环可以使用:each方法 data.goodList.each(function(i,_this){ // 在这里拼接 }) 还有一种方法使用template.js

$(function(){ $.ajax({ type:'GET', url:'{siteurl($siteid)}/api.php', dataType:'json', success: function(data) { var wrap = $("#a"); for(var key in data) { wrap.append($("").html(key + ': ' + data[key])); } } });});

json数组用js解析并显示的方法: 假如后台返回的数据是: {'id':1,'name':'st','grant':[{'tm_id':1,'tm_name':'zc'},{'tm_id':2,'tm_name':'ww'}]} 前台获取: var data = eval_r("(" + json + ")");//json为接收的后台返回的数据; var id1 = ...

用 for in 循环 遍历 var str = '[{"name":"宗2瓜","num":"1","price":"122"},{"name":"宗呱呱","num":"1","price":"100"}]';var xqo = eval('(' + str + ')');for(var i in xqo){alert(xqo[i].name);}

window.onload = function () { var datanav = [{ "name": "张三", "position": "1", "powerrate": "2", "waterrate": "3", "healthcosts": "4", "watermeter": "5", "ammeter": "6", "linkman": "7", "phone": "8", "rental": "9", "tenancy": ...

看这样一段函数定义的代码就明白了function json_to_format_string(obj,deep){var html = "";var blank_string = "";for (var i = 0; i < deep; i++) {blank_string += " ";};for(var name in obj){if (typeof(obj[name])=="object") {html += b...

var typeArr = new Array();for(var i = 0;i

$.each(data,function(i,n){ alert(n.admin_id); });

普通的数组格式是:['a','b','c'] JSON的格式是:{'1':'a','2':'b','3':'c'} 所以把数组循环一下就可以了; var a = ['a','b','c'];var json = {};for(var i=0;i

网站首页 | 网站地图
All rights reserved Powered by www.lxfp.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com