Ajax handles problems with JSON arrays returned by PHP

Source: Internet
Author: User
Ajax handles JSON array problems returned by PHP
{"Status": 1, "info": ["201209\/20120905rmyr8izms6.jpeg", "201209\/20120905b1i8bi1c9x.jpeg", "201209\/ 20120905z0zfdjuf61.jpeg "," 201209\/20120905144fn9ollz.jpeg "]," Data ":" "}


This is the returned data, info inside is an array, I want to use JS effect to turn over the picture, how can I get the picture of the following table and determine whether there is a previous or next picture

------Solution--------------------
My understanding is that you can first parse the JSON data into groups, and then you can get info data, according to the above format, subscript should be the number increment, starting from 0, you can get the length of the info array, you can get the last picture of the subscript, so whether it can be judged? As for the JSON data parsing array, you can go to the web to check, the package of many libraries, the common can be the next Json.js library (www.json.org), and then use String.parsejson () conversion.
In fact, like you said this effect, online should have a lot of examples, you can check the ~
------Solution--------------------
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 length 4var i=3;// Test the last element if ("undefined" = = typeof (Obj.info[(i+1))) {alert (321);} Else{alert (obj.info[(i))} 
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.