如何计算JSON数组元素的长度 [英] how to count length of the JSON array element

查看:417
本文介绍了如何计算JSON数组元素的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试计算JSON数组元素的长度。我知道使用 json.array.length 来计算数组的长度。这需要找到每个索引中有多少项。

I'm trying to count the length of the JSON array element. I know to count the length of array using json.array.length. That is need to find that how many items in every index.

如果我的数组是:

  {"shareInfo":[{"id":"1","a":"sss","b":"sss","question":"whi?"},
  {"id":"2","a":"sss","b":"sss","question":"whi?"},
  {"id":"3","a":"sss","b":"sss","question":"whi?"},
  {"id":"4","a":"sss","b":"sss","question":"whi?"}]}

然后我需要找的长度{id:1,a:sss,b:sss,问题:whi?} 。在这有四个项目。我用 data.shareInfo [i] .length 尝试了这个。但它会产生错误。

Then I need to find the length of {"id":"1","a":"sss","b":"sss","question":"whi?"}. In this there have four items. I tried this with data.shareInfo[i].length. But it produces error.

请有人告诉我如何找到长度....谢谢....

Please anyone tell me how to find the length.... Thanks....

推荐答案

在开始回答之前,请先阅读文档一次。然后你清楚地理解答案。

Before going to answer read this Documentation once. Then you clearly understand the answer.

试试这可能对你有用。

Object.keys(data.shareInfo[i]).length

这篇关于如何计算JSON数组元素的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆