2

This is My JSON Data

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"
}];

how to pick particular data from it using javascript

var day_meal= data.day_meal;
  • 1
    Its an array. Try using data[0].day_meal – Krishna Prashatt Apr 24 '19 at 08:14
  • var test =data[0].day_meal; alert(test); undefined – Swarup Koley Apr 24 '19 at 08:15
  • 1
    You JSON is not properly escaping the quotes, and thus, is invalid JSON. – connexo Apr 24 '19 at 08:16
  • You should use single quotes for the surrounding quotes, if not your compiler will scream at you.. – wentjun Apr 24 '19 at 08:16
  • i am check the json data with json formattor and validator [ { "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" } ] – Swarup Koley Apr 24 '19 at 08:19

1 Answers1

1

The given data is stringified form of the JSON so you first need to parse that to get the actual array and since this array has one object you can access that object with index 0 and after that access the day_meal property of that object:

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);
Ankit Agarwal
  • 30,378
  • 5
  • 37
  • 62