JSON Objects

Answered a question on StackOverflow that I thought is worth posting about.  It’s surprising how many people try to work with JSON without knowing  javascript.

Most JSON either returns objects {} or arrays [].  The first thing you learn about JSON is that you can just eval the object. In the case of arrays, you have to remember deal with them as such.  For example…

    $(document).ready(function(){
       var a = eval("[1,2,3]");
       for(var i in a) {
        $("#results").append(a[i]);
       }
    });

Posted

in

, ,

by

Tags: