phpjson引号转义字符,PHPJSON字符串,转义JS输出的双引号我正在从⼀个
PHP数组创建⼀个JSON字符串.我已经使⽤json_encode()编码了它.
$json_array = array(
'title' => 'Example string\'s with "special" characters'
);
$json_decode = json_encode( $json_array );
在JS⽂件中,我可以通过以下⽅式访问信息:
注意:$json_decode使⽤wp_localize_script()本地化到全局变量PHP_params
var discographyJsonString = PHP_params.place( /"/g,'"' ),discographyJson = jQuery.parseJSON( discographyJsonString );
console.log(discographyJson);
phpjson格式化输出输出结果为:
{ "title":"Example string's with "special" characters" }
从PHP中创建JSON字符串的最佳⽅式是什么,并将其转义为正确使⽤在JS⽂件中?
301_18@
@H_301_18@
从
That said,quotes ” will produce invalid JSON,but this is only an issue if you’re using json_encode() and just expect PHP to magically escape your quotes. You need to do the escaping yourself.
@H_301_18@
总结
如果觉得编程之家⽹站内容还不错,欢迎将编程之家⽹站推荐给程序员好友。
本图⽂内容来源于⽹友⽹络收集整理提供,作为学习参考使⽤,版权属于原作者。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论