Javascript/Jquery解析Json请求
因此,我的页面向一个php页面发出请求,该页面返回一个带有数组结果的JSON PHP返回示例:Javascript/Jquery解析Json请求,javascript,jquery,json,Javascript,Jquery,Json,因此,我的页面向一个php页面发出请求,该页面返回一个带有数组结果的JSON PHP返回示例:{“name”:[“Zizi”,“Zizi”],“position”:[“86”,“86”],“points”:[“26”,“26”]} 每个名称、位置(json数组?)都有多个值我如何解析非常类似于值的值 我正在使用以下代码: $('#getdata-button').live('click', function(){ $.getJSON('all.php', function(dat
{“name”:[“Zizi”,“Zizi”],“position”:[“86”,“86”],“points”:[“26”,“26”]}
每个名称、位置(json数组?)都有多个值我如何解析非常类似于值的值
我正在使用以下代码:
$('#getdata-button').live('click', function(){
$.getJSON('all.php', function(data) {
$('#showdata').html("<p>item1="+ data.name +"</p>");*/
});
});
$(“#获取数据按钮”).live('click',function(){
$.getJSON('all.php',函数(数据){
$('#showdata').html(“item1=“+data.name+””)*/
});
});
有了这个jQuery类型Zizi,Zizi,我如何准备或计算“name”中的值呢?
。length
是数组的属性,它给出了它们的计数
这样使用:data.name.length代码>
另外,getJSON
将只提供JSON字符串
你必须解析它
这样做:
$.getJSON('all.php', function(data) {
data = JSON.parse(data);
var length=data.name.length;
$('#showdata').html("<p>item1="+ data.name +"</p>");*/
});
$.getJSON('all.php',函数(数据){
data=JSON.parse(数据);
变量长度=data.name.length;
$('#showdata').html(“item1=“+data.name+””)*/
});
找到了一个解决方案我不知道它是否最正确
$('#getdata-button').live('click', function(){
$.getJSON('all.php', function(data) {
$(data.name).each(function(index){
$('#showdata').append('<p>Name = ' + data.name[index] +' Position= ' + data.position[index] + ' Points = ' + data.points[index] + '</p>');
});
});
});
$(“#获取数据按钮”).live('click',function(){
$.getJSON('all.php',函数(数据){
$(data.name).each(函数(索引){
$('#showdata').append('Name='+data.Name[index]+'Position='+data.Position[index]+'Points='+data.Points[index]+'');
});
});
});
data
是一个对象,使用数据。name
访问对象中name
键的值,并name.length
返回值的长度,该值为数组。data.name.length返回未定义的X: