Get Object in JSON

1

How can I get only the "name":"josimara" property in this code ajax , I'm new to this area, thank you for the help.

<script src="http://www.habbid.com.br/assets/js/jquery-1.9.1.js"type="text/javascript"></script>

<script type="text/javascript">

var yql_url = 'https://query.yahooapis.com/v1/public/yql';

var url = 'https://www.habbo.com.br/api/public/users?name=josimara';

$.ajax({
  'url': yql_url,
  'data': {
    'q': 'SELECT * FROM json WHERE url="'+url+'"',
    'format': 'json',
    'jsonCompat': 'new',
  },
  'dataType': 'jsonp',
  'success': function(response) {
    console.log(response);
    document.getElementById("test").innerHTML = JSON.stringify(response);
  },
  'error': function(error) {
    document.getElementById("test").innerHTML = "error";
  }
});
</script>

<span id='test'>nothing</span>
    
asked by anonymous 03.10.2017 / 20:03

1 answer

4

What you are looking for is

 document.getElementById("test").innerHTML = response.query.results.json.name;

If you look at the JSON that the API returns, these are the properties you have to go through.

Example:

var yql_url = 'https://query.yahooapis.com/v1/public/yql';
var url = 'https://www.habbo.com.br/api/public/users?name=josimara';

$.ajax({
  'url': yql_url,
  'data': {
    'q': 'SELECT * FROM json WHERE url="' + url + '"',
    'format': 'json',
    'jsonCompat': 'new',
  },
  'dataType': 'jsonp',
  'success': function(response) {
    console.log(response);
    document.getElementById("test").innerHTML = response.query.results.json.name;
  },
  'error': function(error) {
    document.getElementById("test").innerHTML = "error";
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="http://www.habbid.com.br/assets/js/jquery-1.9.1.js" type="text/javascript"></script>



<span id='test'>nothing</span>
    
03.10.2017 / 20:09