我在字符串中有一个json对象数组:
[
{
"title": "Ham on Rye",
"alternativeTitles": [],
"secondaryYearSourceId": 0,
"sortTitle": "ham on rye",
"sizeOnDisk": 0,
"status": "released",
"overview": "A bizarre rite of passage at the local deli determines the fate of a generation of teenagers, leading some to escape their suburban town and dooming others to remain…",
"inCinemas": "2019-08-10T00:00:00Z",
"images": [
{
"coverType": "poster",
"url": "http://image.tmdb.org/t/p/original/px7iCT1SgsOOSAXaqHwP50o0jAI.jpg"
}
],
"downloaded": false,
"remotePoster": "http://image.tmdb.org/t/p/original/px7iCT1SgsOOSAXaqHwP50o0jAI.jpg",
"year": 2019,
"hasFile": false,
"profileId": 0,
"pathState": "dynamic",
"monitored": false,
"minimumAvailability": "tba",
"isAvailable": true,
"folderName": "",
"runtime": 0,
"tmdbId": 527176,
"titleSlug": "ham-on-rye-527176",
"genres": [],
"tags": [],
"added": "0001-01-01T00:00:00Z",
"ratings": {
"votes": 5,
"value": 6.9
},
"qualityProfileId": 0
}
]
当我尝试解析json对象数组时,它总是返回一个字符串,因此当我尝试通过以下方式访问它时:
let data = JSON.parse(JSON.stringify(jsonData));
console.log(data[0].title)
它返回一个像“ [”的特定字符,就好像它是一个字符串一样。
问题在于您正在使用的stringify
东西已经是JSON字符串。
更改此:
let data = JSON.parse(JSON.stringify(jsonData));
对此:
let data = JSON.parse(jsonData);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句