6

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.

3
  • How are you iterating through it? Are you parsing it, or are you evaling it? Do you need just certain parts? Commented Jun 26, 2009 at 19:02
  • some good clientside parsing & performance tips from flickr Commented Jun 26, 2009 at 19:09
  • What is the structure of this json..? just a huge object or a huge array of objects..? Commented Jan 17, 2016 at 6:09

2 Answers 2

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)'.

Sign up to request clarification or add additional context in comments.

1 Comment

I assume Alec is using the json dataType in the xhr call therefore jquery will be eval'ing the response.
1

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 complete answer: How do I iterate over a JSON structure?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.