Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get json array value with ajax

i started to learn json and ajax and i have this json file:

{
  "data": {
    "children": [{
      "data": {
        "domain": "some.url.com"
      },
      {
        "data": {
          "domain": "another.url.com"
        }
      }
    }]
  }
}

How i get the first domain from this file?

I try:

$(document).ready(function(){
  $.getJSON("https://myurl.com/api.json", function(data){
    console.log(data.children[0].data.domain);
});
});

and it didn't work :(

like image 770
Fernando Avatar asked Jun 26 '26 18:06

Fernando


1 Answers

Look closely on your data and your code.

You've got data variable, then data object with children array so you can access it like that

data.data.children[0].data.domain
like image 160
Elon Than Avatar answered Jun 29 '26 09:06

Elon Than



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!