Home > Backend Development > PHP Tutorial > ajax 处理php返回的json 数组有关问题

ajax 处理php返回的json 数组有关问题

WBOY
Release: 2016-06-13 13:14:45
Original
1033 people have browsed it

ajax 处理php返回的json 数组问题
{"status":1,"info":["201209\/20120905rmyr8iZMs6.jpeg","201209\/20120905b1i8bI1C9x.jpeg","201209\/20120905Z0zFDjUF61.jpeg","201209\/20120905144fN9oLlz.jpeg"],"data":""}


这是返回的数据,info里面是一个数组,我想用js特效翻图片,我怎么获取图片的下表并判断有没有上一张或下一张图片

------解决方案--------------------
我的理解是,可以先把json数据解析成数组,然后就能得到info的数据,按照上面的格式,下标应该是数字递增的,从0开始,可以得到info数组的长度,也就能得到最后一张图片的下标了,这样是否可以判断?至于json数据解析数组,可以去网上查下,封装的库很多,常见的可以下个json.js的库(www.json.org),然后用string.parseJSON()转化。
其实像你说的这种效果,网上应该有很多示例的,可以查下~
------解决方案--------------------

JScript code

var str='{"status":1,"info":["201209\/20120905rmyr8iZMs6.jpeg","201209\/20120905b1i8bI1C9x.jpeg","201209\/20120905Z0zFDjUF61.jpeg","201209\/20120905144fN9oLlz.jpeg"],"data":""}';

var obj = eval('(' + str + ')');
alert(obj.info.length);//info长度 为4
var i=3;//测试最后一个元素
if("undefined" == typeof(obj.info[(i+1)])){
alert(321);
}else{
alert(obj.info[(i)])
} <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template