JSON到javascript对象,然后选择项目

时间:2017-02-20 01:55:24

标签: javascript jquery json ajax

我通过ajax从数据库返回JSON值列表:


[] Prevent caching of objects after settings change 
Whenever settings are changed, a new query string will be generated and appended to objects allowing the new policy to be applied.

我希望在使用parse.JSON(obj)之后,我可以将项目推送到javascript变量并在必要时选择:

[{"Month":"02-2017","total":"10","total_2":"36"},{"Month":"01-2017","total":"74","total_2":"51"},{"Month":"12-2016","total":"26","total_2":"47"},{"Month":"11-2016","total":"307800","total_2":"111"}]

选择"值[index] .Month"或类似的东西。

这样做的好方法是什么?

答案: 这种方式效果很好:

                    var values = [];

                    $.ajax({
                        url:'data.php?values=yes',
                        dataType: 'json',
                        success:function(data){

                           $.each(data, function(key, item) {
                                //console.log(item);
                                values.push(item);
                            });


                        }
                    });

0 个答案:

没有答案