我只需要值.how从这些json中获取值
-wafer, -Compound Chocolate, -Praline Chcolate etc.....
在这个主要问题是"子类别"它的值取自数据库,根据数据库的变化
[{"subcategory":"Wafer"},{"subcategory":"Compound Chocolate"},{"subcategory":"Praline Chcolate"},{"subcategory":"Cookies"},{"subcategory":"Toffee"},{"subcategory":"Eclair"},{"subcategory":"Fruit Chews"}]
每个json都有一个像子类别
的值答案 0 :(得分:0)
小提琴:http://jsfiddle.net/KGms7/
var str = '[{"subcategory":"Wafer"},{"subcategory":"Compound Chocolate"},{"subcategory":"Praline Chcolate"},{"subcategory":"Cookies"},{"subcategory":"Toffee"},{"subcategory":"Eclair"},{"subcategory":"Fruit Chews"}]';
var jsn = JSON.parse(str);
var arr = [];
for(var i in jsn) {
arr.push(jsn[i].subcategory);
}
alert(arr);