gpt4 book ai didi

javascript - 字符串到 json 转换器 laravel 返回数据 json_encode

转载 作者:行者123 更新时间:2023-11-28 17:01:23 25 4
gpt4 key购买 nike

"[{"question":false,"choices":["Database","Email","Command line"],"correctAnswer":1},{"question":false,"choices":["Horizon","Sunset","Nightfall"],"correctAnswer":1}]"

转换成这个

[{"question":false,"choices":["Database","Email","Command line"],"correctAnswer":1},{"question":false,"choices":["Horizon","Sunset","Nightfall"],"correctAnswer":1}]

最佳答案

而不是(无效字符串)

"[{"question":false,"choices":["Database","Email","Command line"],"correctAnswer":1},{"question":false,"choices":["Horizon","Sunset","Nightfall"],"correctAnswer":1}]"

使用这个

'[{"question":false,"choices":["Database","Email","Command line"],"correctAnswer":1},{"question":false,"choices":["Horizon","Sunset","Nightfall"],"correctAnswer":1}]'

例如:

var str = '[{"question":false,"choices":["Database","Email","Command line"],"correctAnswer":1},{"question":false,"choices":["Horizon","Sunset","Nightfall"],"correctAnswer":1}]'
console.log(JSON.parse(str))

原因:如果字符串内有双引号,则不能使用双引号将该字符串括起来。由于 JSON 字符串内总是有双引号,因此您可以使用单引号('')或模板字符串(``)将其括起来。

关于javascript - 字符串到 json 转换器 laravel 返回数据 json_encode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57353035/

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