我试图添加微数据到我的网站。有JSON数组。但它是无效的,因为数组键。
我添加数组数据如下:
$data[] = $extra_array_data;
我会假设这不会让我得到数组键0,1,2,3,4等。
但是当它转换为JSON时,它会这样做。
{
"@context": "https://schema.org",
"@graph": {
"0": {
"@type": [
"WebPage"
],
"@id": "https://example.com/#website",
"url": "https://example.com/",
"name": "example.com",
"description": null,
"inLanguage": "nl"
},
"@type": [
"WebPage"
],
"@id": "https://example.com/#webpage",
"url": "https://example.com/contact",
"name": null,
"isPartOf": {
"@id": "https://example.com#website"
},
"datePublished": "2023-03-13T21:29:43.3600Z",
"dateModified": "2023-03-13T21:29:43.3600Z",
"description": "",
"inLanguage": "nl-NL",
"potentialAction": {
"@type": "ReadAction",
"target": [
"https://example.com/contact"
]
}
}
}
我希望有人能告诉我我犯了什么错误。
$json_data = json_encode($return_data, JSON_UNESCAPED_UNICODE);
1条答案
按热度按时间omqzjyyz1#
如果你想让你的
$extra_array_data
替换现有的键,那么你需要合并数组: