How to access data on the third level of a JSON array Object Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How to access data on the third level of a JSON array Object without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I am taking a chance in posting this message for help after looking through over 20+ questions. I could not find an array like the one that I have.

The good news is that I have half of the data that I want from the array. I am missing one last piece of information.

Here is my code.

xhr.onload = function() {
    if(this.status === 200) {
        let response = JSON.parse(this.responseText);
        console.log(response);
        response.rows.forEach(function(row) {
            output += `
            <div>
                <p>${row.number_e164}, ${row.regional_data.rate_center}, ${row.regional_data.rate_center.state}</p>
            </div>
            `;
        })
        document.getElementById('numberdisplay').innerHTML = output;
    }
}
xhr.open('POST', 'provision_helper.php', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.send(data);

Here is a portion of the array.

screenshot of returned object

This displays the number rate center but not the number.

 <p>${row.number_e164}, ${row.regional_data.rate_center}, ${row.regional_data.rate_center.state}</p>

I have tried

 <p>${row.number_e164}, ${row.regional_data.rate_center}, ${row.regional_data.rate_center['state']}</p>

That did not work and just adding state does not work. I can see that the regional data has a different structure. How do I access the state and country iso inside the regional data?

Answer

It looks like you are trying to reference them as being inside rate_center, which isn’t correct. Try row.regional_data.state and row.regional_data.country_iso instead.

We are here to answer your question about How to access data on the third level of a JSON array Object - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji