且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在javascript中将json格式的字符串转换为json数组

更新时间:2023-01-16 19:50:34

如果您没有'['']'字符,则您的字符串不是有效的JSON.

Your string isn't valid JSON if you don't have the '[' and ']' characters.

您可以在中添加它们,然后使用 jQuery.parseJSON() [ docs] 方法.

You can add those in , then parse it using the jQuery.parseJSON()[docs] method.

elements = jQuery.parseJSON( '[' + data + ']' );

...但是***是从服务器发送正确的JSON数据.

...but it would be better if you sent correct JSON data from the server.

此外,您的JSON密钥必须用双引号引起来.

Also, your JSON keys must be wrapped in double quotes.

{"elementid":10},{"elementid":11},{"elementid":12},{"elementid":14},{"elementid":15}