如何把josn数据赋给前端页面

josn数据如下:

 {"pageList":[{"id":"35c12eda2105417d89b981af253180b0","startDate":"2016-08-30 10:12","finlePrice":2,"title":"全新iphone6s爱心舍出","iconsPath":"http://imggoods.shanying.org.cn/goods/20160830/1472523038125.jpeg","sort":71,"endDate":"2016-09-05 00:00","startPrice":1},{"id":"611e9cf935434f5b89051b5faccd50a9","startDate":"2016-08-28 22:27","finlePrice":0,"title":"好大一瓶绝对伏特加","iconsPath":"http://imggoods.shanying.org.cn/goods/20160828/1472394483800.jpg","sort":64,"endDate":"2016-09-04 00:00","startPrice":500},{"id":"e90f27267fe74722932862490a8bd0dc","startDate":"2016-08-10 12:00","finlePrice":1001,"title":"我的相机","iconsPath":"http://imggoods.shanying.org.cn/goods/20160801/1470042973592.jpg","sort":36,"endDate":"2016-12-10 12:00","startPrice":100},{"id":"8ca70fece0ef480d82d6634c6979f750","startDate":"2016-08-01 10:00","finlePrice":3850,"title":"我的IPHONE","iconsPath":"http://imggoods.shanying.org.cn/goods/20160801/1470042344513.png","sort":35,"endDate":"2016-12-20 10:00","startPrice":500}],"maxSort":71,"minSort":35,"success":true,"code":"UGF0000","message":"请求成功"}

把以上数据给前端页面显示列表:

ID 名称 图片 时间
13 标题1 图片 1 2016-08-09
12 标题1 图片 2 2016-08-07
11 标题1 图片 3 2016-08-06

3个回答

前端JavaScript eval 解析 然后在循环赋值

var data =eval(json.pagelist);
data.id,data.name
……
应该就这样

前面的那个连循环都没有,后面那可是一个json'数组啊!

怎莫说也该有个for循环:

 $.ajax({
                type : "POST",
                url : "/api/test",
                dataType : "json",
                data : {},
                success : function(test) {
                    var text;
                    var select = document.getElementById("select");
                    $.each(test, function(i, n) {
                        text = n.text;
                        console.log(text);
                        select.add(new Option(text, i));
                    })

                    /* 由于采取了bootstrap-select的样式,这就不是一个普通的select,在动态加载之后必须刷新*/
                    $('.selectpicker').selectpicker('refresh');
                },
            });

上面是采取ajax进行处理的,

最近我在做关于webservices的一个项目,把大家在生产中的最佳实践结合起来!
项目地址:https://github.com/wangmeng1314/BaseWebServices
给个星星呗客官!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!