How to get data from this json?

There is such json:
[
{
 "id": 1,
 "seasons": [
{
 "id": 1,
 "price": 900.0,
]
],
 "video": "http://127.0.0.1:8000/media/ananas_30_15ndF3z.mp4",
 "title": "Series three",
 "description": "ivative",
 "image": "./poster_DLEMCRd.jpg"
}
]

The angular has a filter:
$scope.seasonFilter = function(series) {
 if ($scope.seasonIncludes.length > 0) {
 if ($.inArray(series.seasons.id, $scope.seasonIncludes) < 0) {
 return null;

}
 } else {
}
 return $scope.series;

 };

Error:
if ($.inArray(series.seasons.id, $scope.seasonIncludes) < 0)

TypeError: Cannot read property 'id' of undefined
This object comes:
[{id: 1, seasons: [{id: 1,...}], video: "http://127.0.0.1:8000/media/ananas_30_JYQk0Qf.mp4",...}]
0
:
{id: 1, seasons: [{id: 1,...}], video: "http://127.0.0.1:8000/media/ananas_30_JYQk0Qf.mp4",...}
description
:
"The first series"
id
:
1
image
:
"./cont-img_GAHtslK.jpg"
seasons
:
[{id: 1,...}]
0
:
{id: 1,...}
description
:
"The first season"
id
:
1
image
:
"./body-bg_ur8GGCM.jpg"
price
:
"1000.25"
season_number
:
1
series
:
[{id: 1, title: "episode 1", video: "./ananas_30_JYQk0Qf.mp4", description: "First series",...}]
show
:
[{id: 1, image: "http://127.0.0.1:8000/media/poster_tBeKJsn.jpg", preview: null, title: "chop",...}]
title
:
"Season 1"
title
:
"1 series"
video
:
"http://127.0.0.1:8000/media/ananas_30_JYQk0Qf.mp4"
July 8th 19 at 11:32
2 answers
July 8th 19 at 11:34
Solution
series[0].seasons[0].id?

Upd:
JSON copied or hand written?
If the former, then there are two errors. After the price shouldn't be the comma and the parenthesis should be braces, not square.

2YXrzda.png
TypeError: Cannot read property 'seasons' of undefined - Chaim27 commented on July 8th 19 at 11:37
: Make console.log(series) and show what happened - beatrice_Hamill1 commented on July 8th 19 at 11:40
Object {id: 2, title: "the Second series second season" video: "./ananas_30_WYgP90y.mp4", description: "Second episode of the second season", image: "./serial-img.jpg"...}
$$hashKey
:
"object:17"
description
:
"The second episode of the second season"
id
:
2
image
:
"./serial-img.jpg"
title
:
"The second episode of the second season"
video
:
"./ananas_30_WYgP90y.mp4"
__proto__
:
Object
posts_controller.js:63
Object {id: 3, title: "Series three", video: "./ananas_30_15ndF3z.mp4", description: "ivative", image: "./poster_DLEMCRd.jpg"...}
$$hashKey
:
"object:18"
description
:
"ivative"
id
:
3
image
:
"./poster_DLEMCRd.jpg"
title
:
"Series three"
video
:
"./ananas_30_15ndF3z.mp4"
__proto__
:
Object
posts_controller.js:63
Object {id: 2, title: "the Second series second season" video: "./ananas_30_WYgP90y.mp4", description: "Second episode of the second season", image: "./serial-img.jpg"...}
$$hashKey
:
"object:17"
description
:
"The second episode of the second season"
id
:
2
image
:
"./serial-img.jpg"
title
:
"The second episode of the second season"
video
:
"./ananas_30_WYgP90y.mp4"
__proto__
:
Object
posts_controller.js:63
Object {id: 3, title: "Series three", video: "./ananas_30_15ndF3z.mp4", description: "ivative", image: "./poster_DLEMCRd.jpg"...}
$$hashKey
:
"object:18"
description
:
"ivative"
id
:
3
image
:
"./poster_DLEMCRd.jpg"
title
:
"Series three"
video
:
"./ananas_30_15ndF3z.mp4"
__proto__
:
Object - Chaim27 commented on July 8th 19 at 11:43
: Anything is unclear. There is series? If not, seek error, if Yes, then better screen lay out - beatrice_Hamill1 commented on July 8th 19 at 11:46
And this is a series, Then series[0].seasons[0].id should work, above the screen. - beatrice_Hamill1 commented on July 8th 19 at 11:49
copied - Chaim27 commented on July 8th 19 at 11:52
: not working, I have no idea why - Chaim27 commented on July 8th 19 at 11:55
:
$scope.seasonFilter = function(series) {
console.log(typeof(series))
if ($scope.seasonIncludes.length > 0) {
if ($.inArray(series[0].seasons[0].id, $scope.seasonIncludes) < 0) {
console.log(series)
return null;

}
} else {
}
return $scope.series;

};

tyeof says that the object comes - Chaim27 commented on July 8th 19 at 11:58
: [{id: 1, seasons: [{id: 1,...}], video: "127.0.0.1:8000/media/ananas_30_JYQk0Qf.mp4",...}]
0
:
{id: 1, seasons: [{id: 1,...}], video: "127.0.0.1:8000/media/ananas_30_JYQk0Qf.mp4",...}
description
:
"The first series"
id
:
1
image
:
"./cont-img_GAHtslK.jpg"
seasons
:
[{id: 1,...}]
0
:
{id: 1,...}
description
:
"The first season"
id
:
1
image
:
"./body-bg_ur8GGCM.jpg"
price
:
"1000.25"
season_number
:
1
series
:
[{id: 1, title: "episode 1", video: "./ananas_30_JYQk0Qf.mp4", description: "First series",...}]
show
:
[{id: 1, image: "127.0.0.1:8000/media/poster_tBeKJsn.jpg", preview: null, title: "chop",...}]
title
:
"Season 1"
title
:
"1 series"
video
:
"127.0.0.1:8000/media/ananas_30_JYQk0Qf.mp4"
This object - Chaim27 commented on July 8th 19 at 12:01
shew that outputs JSON.stringify(series). And series, and the whole object. - gustave_Kertzmann52 commented on July 8th 19 at 12:04
July 8th 19 at 11:36
JSON is not valid, put a comma after 900.0
cut off the excess before inserting here, all valid - Chaim27 commented on July 8th 19 at 11:39
: alas no, after 900.0 past the comma and instead of square braces.

var str = '[{\
 "id": 1,\
 "seasons": [{\
 "id": 1,\
 "price": 900.0\
}],\
 "video": "http://127.0.0.1:8000/media/ananas_30_15ndF3z.mp4",\
 "title": "Series three,"\
 "description": "ivative",\
 "image": "./poster_DLEMCRd.jpg"\
}]';

var tmp = JSON.parse(str);
console.log(tmp[0].seasons[0].id);
- beatrice_Hamill1 commented on July 8th 19 at 11:42

Find more questions by tags JavaScriptAngularDjango