如何在javascript中解析数据

如何在javascript中解析数据,javascript,json,jsonparser,Javascript,Json,Jsonparser,使用免费RESTAPI:获取 100张专辑。并将html页面上的所有相册显示为: UserId: value of userId from the object that came to you, Id: Id value from the object that came to you, Title: title value from the object that came to you As a result, 100 different albums should be pars

使用免费RESTAPI:获取 100张专辑。并将html页面上的所有相册显示为:

 UserId: value of userId from the object that came to you,
 Id: Id value from the object that came to you,
 Title: title value from the object that came to you
 As a result, 100 different albums should be parsed on your page.
我尝试解析数据,数据使用JSON.parse()成为JavaScript对象,但数据以JSON格式显示

<h2>The XMLHttpRequest Object</h2>
<button type="button" onclick="loadDoc()">Change Content</button>
</div>

<script>
function loadDoc() {
 const xhttp = new XMLHttpRequest();
 const url = "https://jsonplaceholder.typicode.com/albums";
 xhttp.onreadystatechange = function() {
   if (this.readyState == 4 && this.status == 200) {
     document.getElementById("demo").innerHTML =
     this.responseText;
   }
 };

 xhttp.open("GET", url, true);
 xhttp.send();
}
</script>
XMLHttpRequest对象
更改内容
函数loadDoc(){
const xhttp=new XMLHttpRequest();
常量url=”https://jsonplaceholder.typicode.com/albums";
xhttp.onreadystatechange=函数(){
if(this.readyState==4&&this.status==200){
document.getElementById(“demo”).innerHTML=
这个.responseText;
}
};
xhttp.open(“GET”,url,true);
xhttp.send();
}

如果添加一个
,它可以正常工作:

函数loadDoc(){
const xhttp=new XMLHttpRequest();
常量url=”https://jsonplaceholder.typicode.com/albums";
xhttp.onreadystatechange=函数(){
if(this.readyState==4&&this.status==200){
document.getElementById(“demo”).innerHTML=
这个.responseText;
}
};
xhttp.open(“GET”,url,true);
xhttp.send();
}
XMLHttpRequest对象
更改内容

那么错误是什么?如果JSON.parse()抛出一个错误,听起来好像它不是有效的JSON。我添加了JSON.parse(…)它不工作。我尝试了你的代码,JSON.parse工作了
var obj=JSON.parse(this.responseText);console.log(obj)
因此不确定您做错了什么。请举例说明错误。在控制台中查找错误。它在console.log()中工作,但在html页面中不工作。什么不工作?它是否打印
[object]