gpt4 book ai didi

php - 在具有多个对象的字符串上使用 eval

转载 作者:行者123 更新时间:2023-11-30 13:05:59 27 4
gpt4 key购买 nike

如何将以下字符串评估为多个对象?目前它只执行第一个然后忽略其余部分,忽略 PHP,这是通过 PHP 生成的,这就是我需要评估它的原因,以便我可以将它用作 jQuery 插件的选项。

            {
latLng:['.$result->lat.','.$result->lon.'],
options:
{
shadow:
{

url: "'.BASE_URL.'css/png/markerBg.png",
scaledSize:
{
width:40,
height:43.5
}
},
icon:
{
url: "'.$result->user->profileImage.'",
scaledSize:
{
width:32,
height:32
},
anchor:
{
x: 16,
y: 40
}

}

}

},
{
latLng:['.$result->lat.','.$result->lon.'],
options:
{
shadow:
{

url: "'.BASE_URL.'css/png/markerBg.png",
scaledSize:
{
width:40,
height:43.5
}
},
icon:
{
url: "'.$result->user->profileImage.'",
scaledSize:
{
width:32,
height:32
},
anchor:
{
x: 16,
y: 40
}

}

}

},
{
latLng:['.$result->lat.','.$result->lon.'],
options:
{
shadow:
{

url: "'.BASE_URL.'css/png/markerBg.png",
scaledSize:
{
width:40,
height:43.5
}
},
icon:
{
url: "'.$result->user->profileImage.'",
scaledSize:
{
width:32,
height:32
},
anchor:
{
x: 16,
y: 40
}

}

}

}

最佳答案

我会避免执行 eval - JSON.parse() 更安全。因为看起来对象已经用逗号分隔了,所以你应该能够将它变成一个数组并解析它。例如,

var objectArray = JSON.parse('[' + objectString + ']');

其中 objectString 具有您在上面粘贴的值。 objectArray 现在将是一个数组,其中包含您的每个对象。

关于php - 在具有多个对象的字符串上使用 eval,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15686147/

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