[英]How to count number of JSON elements in an array in C#
I'm worinkg with instagram API and when I'm receiving recent media with any hashtag by this template: https://api.instagram.com/v1/tags/ {hashtag}/media/recent I'm receiving data like this: 我正在尝试使用Instagram API,当我通过此模板收到带有任何主题标签的最新媒体时: https ://api.instagram.com/v1/tags/ {hashtag} / media / recent我正在接收这样的数据:
{
"pagination": {
"next_max_tag_id": "any_number",
"deprecation_warning": "next_max_id and min_id are deprecated for this endpoint; use min_tag_id and max_tag_id instead",
"next_max_id": "any_number",
"next_min_id": "any_number",
"min_tag_id": "any_number",
"next_url": "https://api.instagram.com/v1/tags/{hashtag}/media/recent?access_token={my_personal_access-token}"
},
"meta": {
"code": 200
},
"data": [
{
"attribution": null,
"tags": [
"any_tag",
"any_tag1",
"any_tag2",
"any_tag3"
],
"type": "image",
"location": null,
"comments": {
"count": 0,
"data": []
},
"filter": "Normal",
"created_time": "any_number",
"link": "any_url",
"likes": {
"count": 0,
"data": []
},
"images": {
"low_resolution": {
"url": "any_url",
"width": 320,
"height": 320
},
"thumbnail": {
"url": "any_url",
"width": 150,
"height": 150
},
"standard_resolution": {
"url": "any_url",
"width": 640,
"height": 640
}
},
"users_in_photo": [],
"caption": {
"created_time": "any_number",
"text": "any_content",
"from": {
"username": "any_username",
"profile_picture": "any_url",
"id": "any_number",
"full_name": "any_full_name"
},
"id": "any_number"
},
"user_has_liked": false,
"id": "any_number",
"user": {
"username": "any_username",
"profile_picture": "any_url",
"id": "any_number",
"full_name": "any_full_name"
}
},
and so on. 等等。 As You can see, object "data" is an Array, and further we can see object "tags", which is also array. 正如您所看到的,对象“data”是一个数组,我们还可以看到对象“tags”,它也是数组。 how can I check number elements array of array in C#? 如何在C#中检查数组的数组元素数组? i tried like this: 我试过这样的:
JArray items = (JArray)jsonData["data[0].tags"];
int length = items.Count;
but it doesn't work. 但它不起作用。 I parse JSON like this: 我像这样解析JSON:
dynamic jsonData = JsonConvert.DeserializeObject<dynamic>(JSON_string);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.