admin管理员组文章数量:1277317
the output of the code below is this:
[{"user_name":"Maria","user_surname":"Dominguez"},{"user_name":"Celia","user_surname":"Paris"}]
95
I expected the length be 2. Any explanation?
$.get(
"/school/view-more-users",
{"type": user_type, "school_id": school_id, "offset": offset},
function(data){
console.log(data);
console.log(data.length);
,
"json"
);
Javier
the output of the code below is this:
[{"user_name":"Maria","user_surname":"Dominguez"},{"user_name":"Celia","user_surname":"Paris"}]
95
I expected the length be 2. Any explanation?
$.get(
"http://myfirm.local/school/view-more-users",
{"type": user_type, "school_id": school_id, "offset": offset},
function(data){
console.log(data);
console.log(data.length);
,
"json"
);
Javier
Share Improve this question edited Jun 18, 2012 at 10:48 Alex K. 176k32 gold badges274 silver badges295 bronze badges asked Jun 18, 2012 at 10:40 user1077220user1077220 1,5235 gold badges17 silver badges21 bronze badges 1- using $.each to deal with it, you don't need to know how many elements I think. – Tom Commented Jun 18, 2012 at 10:55
3 Answers
Reset to default 4data= JSON.parse(data);
console.log(data.length);
OR
data= $.parseJSON(data);
console.log(data.length);
The console.log will output you 95 because it interprets your data object as a string which in fact has exactly 95 characters.
because you are looking at the length of string. Try parsing it in JSoN object and see the length
$.parseJSON(data)
本文标签: javascriptData length in JSON response dataStack Overflow
版权声明:本文标题:javascript - Data length in JSON response data - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741276493a2369758.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论