这是我正在使用的json:
{
"rsid": "xyz",
"globalFilters": [
{
"type": "segment",
"segmentId": "123"
},
{
"type": "dateRange",
"dateRange": "2019-01-01T00:00:00.000/2019-02-01T00:00:00.000"
}
],
"metricContainer": {...
我正在尝试使用以下代码替换dateRange的值:
$data = json_decode($data,true);
$data['globalFilters'][0]['dateRange'] = $daterange;
$data = json_encode($data);
echo ($data);
但是这样会导致在段ID:“ 123”下添加此值,
{
"rsid": "xyz",
"globalFilters": [
{
"type": "segment",
"segmentId": "123"
"dateRange": "NEWRANGE"
},
{
"type": "dateRange",
"dateRange": "2019-01-01T00:00:00.000/2019-02-01T00:00:00.000"
}
],
"metricContainer": {...
任何人都可以帮助我了解如何解决此问题吗?
答案 0 :(得分:2)
发生这种情况的原因是因为您访问了错误的变量。您需要访问
$data['globalFilters'][1]['dateRange'] = $daterange;