admin管理员组文章数量:1221774
I would like to count the length of my response JSON. Here's my code:
getMoviesFromApiAsync() {
return fetch('/' + CommonDataManager.getInstance().getUserID())
.then((response) => response.json())
.then((responseJson) => {
this.setState({isLoading: false, listMessages: responseJson});
})
.catch((error) => {
console.error(error);
});
}
I would like to count the length of my response JSON. Here's my code:
getMoviesFromApiAsync() {
return fetch('http://sampleurl.com/' + CommonDataManager.getInstance().getUserID())
.then((response) => response.json())
.then((responseJson) => {
this.setState({isLoading: false, listMessages: responseJson});
})
.catch((error) => {
console.error(error);
});
}
Share
Improve this question
edited Sep 3, 2017 at 9:42
StudioTime
24k40 gold badges128 silver badges215 bronze badges
asked Sep 3, 2017 at 7:35
DeeeDeee
3292 gold badges9 silver badges27 bronze badges
2
- 2 Please read Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers? - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Commented Sep 3, 2017 at 8:19
- 2 You are welcome. The community also prefers titles written in natural English. Grammatically, "React How to count the length of a JSON response" doesn't make a lot of sense (though I understand the purpose of using "ReactJS" as a home-made tag). However, since we have a tagging system, it is better to merge the "tag" into the question, or get rid of it completely, since it is already in the tag list. – halfer Commented Sep 3, 2017 at 8:37
1 Answer
Reset to default 16Count the keys
var myObject = {'key':'something', 'other-key':'something else','another-key': 'another thing'}
var count = Object.keys(myObject).length;
Where myObject
is your json response and count
is the length of your object
This is the best way to count the json objects correctly
In your code you should add this in your second .then
var count = Object.keys(responseJson).length;
本文标签: javascriptHow to count the length of JSON response in React NativeJSStack Overflow
版权声明:本文标题:javascript - How to count the length of JSON response in React NativeJS? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739310639a2157566.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论