【发布时间】:2015-03-03 15:14:02
【问题描述】:
在数据库中,“imgs_urls”字段:
["http://localhost/wordpress-gallery/wp-content/uploads/2015/01/120.jpg","http://localhost/wordpress-gallery/wp-content/uploads/2015/01/222.jpg"]
php:
$images_urls = get_post_meta($user_post, 'imgs_urls', false); //return array
$a = json_encode($images_urls);
<input type="hidden" name="<?php echo $id; ?>urls" id="<?php echo $id; ?>urls" value="<?php echo $a; ?>" />
现在页面加载时的大废话输出:
显然,在我的 js 中,当我尝试这样做时出现错误:
var images = $.parseJSON($("#"+imgId+"urls").val());
编辑
现在,如果我从加载页面时执行的函数中的 js 开始:
var vv = [];
vv.push('http://localhost/wordpress-gallery/wp-content/uploads/2015/01/118.jpg');
vv.push('http://localhost/wordpress-gallery/wp-content/uploads/2015/01/118.jpg');
$("#" + imgId + "urls").val(JSON.stringify(vv));
帖子保存后,在数据库中:
["http://localhost/wordpress-gallery/wp-content/uploads/2015/01/118.jpg","http://localhost/wordpress-gallery/wp-content/uploads/2015/01/118.jpg"]
完全相同的数据库格式,这次没有错误消息:
var images = $.parseJSON($("#"+imgId+"urls").val());
我正在使用相同的 php json_encode 函数...很奇怪,有什么想法吗?
【问题讨论】:
标签: php json wordpress parsing