这是我的JSON数据
var data = [{
meal_com_id: "1",
company_name: "PeryCap",
pic: "https://shopgo.in/upload/1545849409-1518284057-Untitled-nn1.png",
status: "1",
details: "sdvaebfvhjaebfber itnwiuore tg5ykrgt wiretgi34 tgi3rgtiquogtiq",
Address:
"B.L. Behind Dhaldighi Petrol Pump, Burdwan, B.L.Hati Rd, Khosbagan Burdwan West Bengal 713101",
day_meal: "42",
night_meal: "25"
}];
如何使用javascript从中选择特定数据
var day_meal= data.day_meal;
答案 0 :(得分:1)
给定的数据是JSON的字符串形式,因此您首先需要解析它以获得实际的数组,并且由于此数组具有一个对象,因此您可以使用索引0访问该对象,然后访问day_meal
属性该对象的:
var data = '[{"meal_com_id":"1","company_name":"PeryCap","pic":"https://shopgo.in/upload/1545849409-1518284057-Untitled-nn1.png","status":"1","details":"sdvaebfvhjaebfber itnwiuore tg5ykrgt wiretgi34 tgi3rgtiquogtiq","Address":"B.L. Behind Dhaldighi Petrol Pump, Burdwan, B.L.Hati Rd, Khosbagan Burdwan West Bengal 713101","day_meal":"42","night_meal":"25"}]';
var dayMeal = JSON.parse(data)[0].day_meal;
console.log(dayMeal);