Сообщение от FALKOR
|
Строка выглядит примерно следующим образом
'"{"1":{"id":1,"name":"Артикул 2","price":299,"num":1,"url":"http://site/","photo":""},"2":{"id":2,"name":"Артикул 2","price":220,"num":1,"url":"http://site/","photo":""},"3":{"id":3,"name":"Артикул 6","price":179,"num":1,"url":"http://site/","photo":""}}"'
|
Вариант с массивом смотрится более эстетично...
var str='[{"id":1,"name":"Артикул 2","price":299,"num":1,"url":"http://site/","photo":""},{"id":2,"name":"Артикул 2","price":220,"num":1,"url":"http://site/","photo":""},{"id":3,"name":"Артикул 6","price":179,"num":1,"url":"http://site/","photo":""}]'
var a = JSON.parse(str);
var sum=0;
for (var i=0; i<a.length; i++) {
alert(a[i].name);
sum+=a[i].price;
};
alert('sum='+sum);