Hello everyone, I have a lot of JSON data. Now,I want to print them to HTML. Can anyone please help me do this.
I tried with ““document.getElementbyId””
<html>
<head>
<title>hi</title>
</head>
<body>
<h2>Convert a string written in JSON format, into a JavaScript object.</h2>
<p id="output"></p>
<div id="a1"></p>
<script>
var obj = [{
"client_msg_id": "3a223f8d-b5aa-4c9c-9b63-045ec6f90b58",
"type": "message",
"text": "hey there",
"source_team": "TN4AF0V5W",
"team": "TN4AF0V5W",
"user_profile": {
"real_name": "marvelmohinish99",
"team": "TN4AF0V5W"
}
},
{
"client_msg_id": "3a223f8d-b5aa-4c9c-9b63-045ec6f90b58",
"type": "message",
"text": "welcome",
"source_team": "TN4AF0V5W",
"team": "TN4AF0V5W",
"user_profile": {
"real_name": "marvelmohinish99",
"team": "TN4AF0V5W"
}
},
{
"client_msg_id": "3a223f8d-b5aa-4c9c-9b63-045ec6f90b58",
"type": "message",
"text": "Help me",
"source_team": "TN4AF0V5W",
"team": "TN4AF0V5W",
"user_profile": {
"real_name": "marvelmohinish99",
"team": "TN4AF0V5W"
}
}
];
for (i=0;i<=obj.length;i++) {
var type = obj[i].type;
var text = obj[i].text;
var source_team = obj[i].source_team;
var user_profile = obj[i].user_profile;
var real_name = user_profile.real_name;
console.log(text);
console.log(real_name);
document.getElementById("a1").innerHTML= text;
}
</script>
</body>
</html>