0

I know how to put the whole JSON into Javascript, but I don't know how to take 1 object value and put it into a javascript variable.

For example if I wanted the value of "start_time" below, in a variable in Javascript.

{
    "result": {
        "status": 1,
        "num_results": 10,
        "total_results": 500,
        "results_remaining": 490,
        "matches": [
            {
                "match_id": 515853415,
                "match_seq_num": 469991846,
                "start_time": 1392156202,
                "lobby_type": 7,
                "players": [
....
0

2 Answers 2

4
var JS = JSON.parse(yourJSONString);
var start_time = JS.results.matches[0].start_time;
Sign up to request clarification or add additional context in comments.

Comments

0

If you get the json from the back-end via an XHR request then you need to parse it first and convert it into a JavaScript object

var obj = JSON.parse(json);

Then you can access the start_time property as you would access any other property of a JavaScript object

obj.result.matches[0]['start_time']

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.