可能是重复问题:
在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获取返回的元素总数,该怎么办?