ali yami ali yami - 1 year ago 79
JSON Question

Get Results array and count from json responce

I got the following json responce from my odata service:


I have written the following jquery code to get the data but not working

$.getJSON(url, function (data) {
var html = '<div id="products" class="row list-group">';

for (var i = 0;i<data.length;i++)
html += '<div class="item ' + $("#CurrentView").val() + ' col-xs-4 col-lg-4"><div class="thumbnail"><img class="group list-group-image" src="../img/product2.jpg" alt="" /><div class="caption"><h4 class="group inner list-group-item-heading">';
html += data[i].ProductName + '</h4><p class="group inner list-group-item-text"> Product description... </p><div class="row"><div class="col-xs-12 col-md-6"><p class="lead">';
html += data[i].UnitPrice + '</p></div><div class="col-xs-12 col-md-6"><a class="btn btn-success" href="">Add to cart</a></div></div></div></div></div>';
html+= '</div>';

how can i refer to Results array and __count property in jquery?

Answer Source

It should be data.Results.length and data.Results[i].UnitPrice.

data is an object, and Results (the array) is a property of that object. So data.Results will get you the array itself.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download