重複の可能性:
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"
}
]}
これは基本的に、オブジェクトから3つの食品要素を返します。jsonデータが動的であり、jqueryを使用して不明な場合、返される要素の総数のカウントを取得するにはどうすればよいですか?