Reading a complex JSON in jQuery
<p>I have the following complex jSON string which gets returned in an Ajax call in jquery 1.8</p>

<pre><code>listCountries({"totalResults":3,"countrynames":[
{"countryName":"Afghanistan","fName":"parks,area, ...","lng":1,"code":"continent"},
{"countryName":"Albenia","fName":"parks,area, ...","lng":2,"code":"continent"},
{"countryName":"Algeria","fName":"parks,area, ...","lng":3,"code":"continent"}
]});
</code></pre>

<p>I want to populate a select box using this JSON data.</p>

<p>I am doing the following</p>

<pre><code> $.getJSON(someurl)
            .success(function (data) {
                var list= "";
                for (var i = 0; i &lt; data.countrynames.length; i++) {
                    list += "&lt;option value='" + data.countrynames[i].lng + "'&gt;" + data.countrynames[i].countryName + "&lt;/option&gt;";
                }
$("#names").html(list);
</code></pre>

<p>However the list does not get populated. Can anyone suggest why. Also is there a better practice to loop through this JSON string and populate select box.</p>
