[英]How to get the data inside a JSON object in jquery
I want to retrieve the data inside a JSON object, but when I tried to alert it, or log it, I got [Object Object] or undefined . 我想检索JSON对象中的数据,但是当我尝试对其进行警报或记录时,得到了[Object Object]或undefined 。 Say I'm getting the json object in a div with id = "page".
假设我在id =“ page”的div中获取json对象。 This's what I did:
这就是我所做的:
console.log($("#page").val()); //gives undefined
console.log($("#page").toString()); // gives [Object Object]
I'm getting the JSON object inside a div I introduced 我在我介绍的div中获取了JSON对象
<div id="page"></div>
From here I was trying to get the JSON object. 从这里开始,我试图获取JSON对象。
So how do I get the data inside this object? 那么如何获取该对象内部的数据?
To log the object of an DOM element simply: 只需记录DOM元素的对象:
console.log($("#page"));
To get the HTML content of it: 要获取其HTML内容:
console.log($("#page").html());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.