gpt4 book ai didi

javascript - 用 JavaScript 将字符串转换为数组?

转载 作者:行者123 更新时间:2023-11-28 02:52:17 24 4
gpt4 key购买 nike

我有一些由 API 返回的数据,这些数据采用字符串格式,我想将其转换为数组,以便我可以从中选取值。

如下所示:

images/20100819_202433.jpg{
"permalink": "http://burstn.com/sayhi#burst/06d67eed55d05dd545583de5b4ca3556",
"total_comments": "0",
"caption": "",
"created_at": "2010-08-20 03:24:35.759172+0000",
"coordinates": {
"latitude": "",
"longitude": ""
},
"public": "False",
"source": "wesbos_webcam",
"total_likes": "0",
"user": {
"username": "sayhi",
"display_name": null,
"permalink": "http://burstn.com/sayhi",
"profile_image": "http://www.gravatar.com/avatar.php?default=http%3A%2F%2Fburstn.com%2Fimages%2Favatar.jpg&size=100&gravatar_id=e1cb97806d9df68d0e5daec9810cb228",
"id": 357
},
"image": {
"large": "http://media.burstn.com/06d67eed55d05dd545583de5b4ca3556-large.jpg",
"width": 500,
"medium": "http://media.burstn.com/06d67eed55d05dd545583de5b4ca3556-medium.jpg",
"square": "http://media.burstn.com/06d67eed55d05dd545583de5b4ca3556-square.jpg",
"thumb": "http://media.burstn.com/06d67eed55d05dd545583de5b4ca3556-thumb.jpg",
"small": "http://media.burstn.com/06d67eed55d05dd545583de5b4ca3556-small.jpg",
"original": "http://media.burstn.com/06d67eed55d05dd545583de5b4ca3556-original.jpg",
"height": 500
},
"id": "06d67eed55d05dd545583de5b4ca3556",
"comments": {
"paging": {
"previous": "",
"next": "http://burstn.com/api/1/comments/?burst_id=06d67eed55d05dd545583de5b4ca3556&page=2"
},
"data": []
}

}

因此,剪掉前面的文本,然后将其余部分转换为数组。我怎样才能用JS做到这一点?

最佳答案

我认为你的意思是将字符串转换为json格式?如果我是对的你可以尝试JSON

它可以将字符串转换为 json,反之亦然。

alert(JSON.decode('[0,1,false,true,null,[2,3],{"some":"value"}]'))

//0,1,false,true,,2,3,[对象对象]

关于javascript - 用 JavaScript 将字符串转换为数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3527978/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com