最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Fastest way to iterate through JSON string in Javascript - Stack Overflow

programmeradmin7浏览0评论

I have been using $.each of the jQuery framework to iterate through a JSON string that I receive via an AJAX call. Now this string is sometimes quite huge and as a result IE6/7/8 crawl as a result.

I am wondering if there is a faster way to iterate through the entire data.

Thank you for your time.

I have been using $.each of the jQuery framework to iterate through a JSON string that I receive via an AJAX call. Now this string is sometimes quite huge and as a result IE6/7/8 crawl as a result.

I am wondering if there is a faster way to iterate through the entire data.

Thank you for your time.

Share Improve this question asked Jun 26, 2009 at 18:58 Alec SmartAlec Smart 96k39 gold badges124 silver badges186 bronze badges 3
  • How are you iterating through it? Are you parsing it, or are you evaling it? Do you need just certain parts? – cgp Commented Jun 26, 2009 at 19:02
  • some good clientside parsing & performance tips from flickr – redsquare Commented Jun 26, 2009 at 19:09
  • What is the structure of this json..? just a huge object or a huge array of objects..? – T J Commented Jan 17, 2016 at 6:09
Add a ment  | 

2 Answers 2

Reset to default 1

How about using the regular javascript functions?

If for example you have a JSON object with items in them, you could just eval the JSON string to convert it to javascript objects, and iterate over them using 'for (i in object)'.

Hope to be still in time!

How about a simple -for-?

for(i = 0; i < data.length; i++) {
    data[i].property = 'todo';
}

Otherwise -for in-

var mycars = [{name:'Ferrari'}, {name:'BMW'}];
for (i in mycars)
{
    document.write(mycars[i].name + "<br />");
}

Here is the plete answer: How do I iterate over a JSON structure?

发布评论

评论列表(0)

  1. 暂无评论