gpt4 book ai didi

php - 防止 json_encode 添加转义字符

转载 作者:行者123 更新时间:2023-12-01 03:03:13 26 4
gpt4 key购买 nike

有没有办法防止 json_encode 添加转义字符?我从 ajax 请求返回一个 json obj。

这是我目前拥有的:

foreach ($files as $file)
{
$inf = getimagesize( $file );

$farr[] = array (
"imgurl" => "/".str_replace( "\\" , "/" , str_replace( DOCROOT , "" , $file ) ) ,
"width" => $inf[0] ,
"height" => $inf[1]
);
}
$t = json_encode( $farr );

它提供:

[
{\"imgurl\":\"\\\/_assets\\\/portfolio\\\/96\\\/full.png\",\"width\":580,\"height\":384},
{\"imgurl\":\"\\\/_assets\\\/portfolio\\\/95\\\/full.png\",\"width\":580,\"height\":452},
{\"imgurl\":\"\\\/_assets\\\/portfolio\\\/94\\\/full.png\",\"width\":580,\"height\":384}
]

但我需要:

[
{imgurl:"/_assets/portfolio/96/full.png",width:580,height:384},
{imgurl:"/_assets/portfolio/95/full.png",width:580,height:452},
{imgurl:"/_assets/portfolio/94/full.png",width:580,height:384}
]

引用 imgurl 宽度和高度索引会导致我的 javascript 的其余部分崩溃

运气不太好,所以非常欢迎任何提示......

最佳答案

使用问题中的代码并对其进行 var_dump,我得到以下内容: string(40) "[{"imgurl":"\/bla"},{"imgurl":"\/blub “}]”

只有当我像 $t = json_encode(json_encode($farr)); 这样将 json_encode 加倍时,我才会得到与你相同的结果 - 所以某处一定有第二个 json_encode...

关于php - 防止 json_encode 添加转义字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6060971/

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