0

in some case i want to show a specific object of JSON file which is load from url in js :

<div id="me2"></div>
<script>
function Get(yourUrl){
    var Httpreq = new XMLHttpRequest(); // a new request
    Httpreq.open("GET",yourUrl,false);
    Httpreq.send(null);
    return Httpreq.responseText;          
}
var json_obj = JSON.parse(Get('https://www.instagram.com/barkobco/?__a=1'));
document.getElementById("me2").innerHTML = json_obj.graphql.user.edge_follow;
</script>
</body>
</html>

but the output is : [object Object]

why?

the correct object value is : 25

  • The code presented does not perform a request in the correct manner. See [MDN's article on the topic for examples](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest). – Heretic Monkey Jun 18 '20 at 12:00
  • Does this answer your question? [How to get the response of XMLHttpRequest?](https://stackoverflow.com/questions/3038901/how-to-get-the-response-of-xmlhttprequest) – Heretic Monkey Jun 18 '20 at 12:00

2 Answers2

1

If you are trying to get the count, you'll have to go 1 more level:

<div id="me2"></div>
<script>
function Get(yourUrl){
    var Httpreq = new XMLHttpRequest(); // a new request
    Httpreq.open("GET",yourUrl,false);
    Httpreq.send(null);
    return Httpreq.responseText;          
}
var json_obj = JSON.parse(Get('https://www.instagram.com/barkobco/?__a=1'));
document.getElementById("me2").innerHTML = json_obj.graphql.user.edge_follow.count;
</script>
</body>
</html>
FrostyZombi3
  • 619
  • 5
  • 13
1

That's because json_obj.graphql.user.edge_follow is still an object you need to find .count of it.

<div id="me2"></div>
<script>
function Get(yourUrl){
    var Httpreq = new XMLHttpRequest(); // a new request
    Httpreq.open("GET",yourUrl,false);
    Httpreq.send(null);
    return Httpreq.responseText;          
}
var json_obj = JSON.parse(Get('https://www.instagram.com/barkobco/?__a=1'));
console.log(json_obj)
document.getElementById("me2").innerHTML = json_obj.graphql.user.edge_follow.count;
</script>
</body>
</html>
ABGR
  • 4,631
  • 4
  • 27
  • 49