JS Simple loop Traversal method of JSON array

Source: Internet
Author: User

For example, the JSON string inside the database is like this

12345 varstr = ‘[{"name":"宗2瓜","num":"1","price":"122"},{"name":"宗呱呱","num":"1","price":"100"}]‘;var xqo = eval(‘(‘ + str + ‘)‘);for(var i inxqo){  alert(xqo[i].name);}

The above is JS, the following is jquery to parse the JSON string,

12 varcc = jQuery.parseJSON(data);alert(cc[0].title);

Loop the words, and the same as above

Finally, the background returns JSON data with Echo, not return, otherwise the front end is not received and will be reported:

Uncaught syntaxerror:unexpected end of JSON input

The reason is: The request background interface is, the background is no response (that is, no response), this situation is either the interface letter is wrong, or the background problem.

JS Simple loop Traversal method of JSON array

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.