Javascript JSON,从字符串中检索
所以我正在为学校开发一个REACT应用程序,我在页面之间传递数据时遇到了问题。我已经设法将对象作为JSON字符串发送,从本地存储获取字符串的代码如下所示Javascript JSON,从字符串中检索,javascript,json,reactjs,Javascript,Json,Reactjs,所以我正在为学校开发一个REACT应用程序,我在页面之间传递数据时遇到了问题。我已经设法将对象作为JSON字符串发送,从本地存储获取字符串的代码如下所示 let show=JSON.parse(localStorage.getItem("SEARCHED_SHOW")) console.log(show) {"id":18,"name":"Steins;Gate","image":"
let show=JSON.parse(localStorage.getItem("SEARCHED_SHOW"))
console.log(show)
{"id":18,"name":"Steins;Gate","image":"nou","no_episodes":25,"description":"a new show","overall_score":0.0,"caracters":[{"id":22,"name":"Okabe","image":"none","description":"new","no_marks":0,"overall_mark":0.0,"shows":null},{"id":32,"name":"Kurisu","image":null,"description":null,"no_marks":0,"overall_mark":0.0,"shows":null}],"reviews":[],"categories":[{"id":40,"name":"SciFi","image":"none","shows":null}]}
控制台上的输出如下所示
let show=JSON.parse(localStorage.getItem("SEARCHED_SHOW"))
console.log(show)
{"id":18,"name":"Steins;Gate","image":"nou","no_episodes":25,"description":"a new show","overall_score":0.0,"caracters":[{"id":22,"name":"Okabe","image":"none","description":"new","no_marks":0,"overall_mark":0.0,"shows":null},{"id":32,"name":"Kurisu","image":null,"description":null,"no_marks":0,"overall_mark":0.0,"shows":null}],"reviews":[],"categories":[{"id":40,"name":"SciFi","image":"none","shows":null}]}
我的问题是如何在页面上显示对象的部分。例如,我想显示对象id,字符串将给我18您可以通过
show.id
show.id在console@AverageSoul是什么让你console.log(show)
还是console.log(show的类型)
?如果控制台为您提供对象
,则。。。嗯,这个.id
应该给你18
我需要知道“console.log(typeof show)”我解决了,这是我的问题,对不起