0

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?

2
  • 2
    You'd get that part with object_name.display_custom_hours ? Commented Oct 15, 2015 at 19:09
  • 2
    You can simply access myObj.display_custom_hours Commented Oct 15, 2015 at 19:09

2 Answers 2

1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

I figured out that the console wouldn't recognize 'display_custom_hours', however it was recognized if i referenced it on the front end of my code. (very strange situation)
1

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

  1. Put your data into a variable var , like this

    var jsonData = '{"display_custom_hours":"Open on Oct 15 from 3:00PM - 4:00PM"}';

  2. Prase it using JSON.parse function , like this

    jsonData = JSON.parse(jsonData);

  3. 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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.