我有以下JSON文件的一部分。我需要使用純Javascript來轉換爲Javascript數組。具體而言,我需要有一個陣列 userid
,movieid
,rating
,timestamp
只對於rating
大於4.0
。使用純Javascript將JSON轉換爲Javascript數組
[{
"rating": 3.0,
"ratingsPK": {
"movieId": 2017,
"userId": 610
},
"timestamp": 913815387
}, {
"rating": 5.0,
"ratingsPK": {
"movieId": 2017,
"userId": 654
},
"timestamp": 959098930
}, {
"rating": 4.0,
"ratingsPK": {
"movieId": 2017,
"userId": 856
},
"timestamp": 1059863336
}, {
"rating": 2.0,
"ratingsPK": {
"movieId": 2017,
"userId": 903
},
"timestamp": 903628492
}, {
"rating": 3.5,
"ratingsPK": {
"movieId": 2017,
"userId": 1185
},
"timestamp": 1100560205
}]
請加通緝的結果,以及,你都試過了。 –
使用'JSON.parse,Array.forEach並將其推送到數組'。檢查我的答案 –