Reputation: 2174
I have a problem in that I need some information from an API, but am not able to dig any further, and as a result i'm only able to dig so far into the api to gather the information that i need, and it is coming as an object. Looking like this:
{"display_custom_hours":"Open on Oct 15 from 3:00PM - 4:00PM"}
However I only need this part
Open on Oct 15 from 3:00PM - 4:00PM
Am I able to use Javascript to manipulate that information to what I need?
Upvotes: 0
Views: 45
Reputation: 697
Try this
var jsonData = '{"display_custom_hours":"Open on Oct 15 from 3:00PM - 4:00PM"}';
jsonData = JSON.parse(jsonData);
alert(jsonData.display_custom_hours);
Solution steps
Put your data into a variable var
, like this
var jsonData = '{"display_custom_hours":"Open on Oct 15 from 3:00PM - 4:00PM"}';
Prase it using JSON.parse
function , like this
jsonData = JSON.parse(jsonData);
You can use your date in this form Object.propriety
, like this
alert(jsonData.display_custom_hours);
Output
Open on Oct 15 from 3:00PM - 4:00PM
Upvotes: 1
Reputation: 1177
If you are already object, try this:
console.log(your_object.display_custom_hours);
If not try this:
var stringObj = '{"display_custom_hours":"Open on Oct 15 from 3:00PM - 4:00PM"}'; // or item received
var obj = JSON.parse(stringObj);
console.log(obj.display_custom_hours);
Upvotes: 1