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

2

2 Answers 2

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>

Sign up to request clarification or add additional context in comments.

Comments

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>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.