0

I have read a lot of Questions here but could find any answer for my Problem with Multidimensional JSON Arrays. I want to just to parse the Tag "countdown" but my Code get only up to the Array "departureTime". Any other change has no result to show the "countdown" tag.

My JSON

    {
    "data": {
        "monitors": [
            {
                "locationStop": {
                    "type": "Feature",
                    "geometry": {
                        "type": "Point"
                    }
                },
                "lines": [
                    {
                        "departures": {
                            "departure": [
                                {
                                    "departureTime": {
                                        "timePlanned": "2016-02-13T23:03:00.000+0100",
                                        "timeReal": "2016-02-13T23:03:39.000+0100",
                                        "countdown": 13
                                    }
                                },
                                {
                                    "departureTime": {
                                        "timePlanned": "2016-02-13T23:33:00.000+0100",
                                        "countdown": 43
                                    }
                                },
                                {
                                    "departureTime": {
                                        "timePlanned": "2016-02-13T23:48:00.000+0100",
                                        "countdown": 58
                                    }
                                }
                            ]
                        }
                    }
                ]
            }
        ]
    }
}

I am parsing like here

success: function(data) {
    var json = $.parseJSON(data);
    var departure = json.data.monitors[0].lines[0].departures.departure;
    $.each(departure, function(i, item) {
        $.each(item, function(i, type) {
            console.log(type);
            $('#results').append(type);
        });

    });
}

Adding a third $.each is not working in any way, I added to $each(departure.departureTime) and to $.each(item.countdown) but this give me Errors too. I am not a developer :(

1 Answer 1

1

Try this:

success: function(data) {
    var json = $.parseJSON(data);
    var departure = json.data.monitors[0].lines[0].departures.departure;
    $.each(departure, function(i, item) {
        $('#results').append(item.departureTime.countdown);
    });
}
Sign up to request clarification or add additional context in comments.

1 Comment

Ohh my God! Never thought about the append. Thanks a lot!

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.