可能重复:
在 jquery 中查找数组的长度(大小)
我有一个从 php 文件返回的 json 对象,如下所示:-
{"food":[
{
"name" :"Belgian Waffles",
"price" :"$5.95",
"description":"two of our famous Belgian Waffles with plenty of real maple syrup",
"calories" :"650"
},
{
"name" :"Strawberry Belgian Waffles",
"price" :"$7.95",
"description":"light Belgian waffles covered with strawberries and whipped cream",
"calories" :"900"
},
{
"name" :"Berry-Berry Belgian Waffles",
"price" :"$8.95",
"description":"light Belgian waffles covered with an assortment of fresh berries and whipped cream",
"calories" :"900"
}
]}
这实质上是从对象返回三个食物元素。如果 json 数据是动态的并且使用 jquery 未知,我如何计算返回的元素总数?