我想插入另一个项目到我现有的JSON数组中。PHP - 在嵌套的JSON数组中添加项目
{
"gallery": [
{
"titel": "Gallery 1",
"thumb": "http://via.placeholder.com/150x150",
"images": [{
"image": "http://via.placeholder.com/150x150"
},{
"image": "http://via.placeholder.com/150x150"
},{
"image": "http://via.placeholder.com/150x150"
},{
"image": "http://via.placeholder.com/150x150"
},{
"image": "http://via.placeholder.com/150x150"
},{
"image": "http://via.placeholder.com/150x150"
}]
}, {
"titel": "Gallery 2",
"thumb": "http://via.placeholder.com/150x150",
"images": [{
"image": "http://via.placeholder.com/150x150"
},{
"image": "http://via.placeholder.com/150x150"
}]
}
]
}
在“相册1”或“图库2”等等... 较宽的图象是要被添加。
如何为相应的“标题”添加新的特定图像?
最实用的方法可能是您的JSON字符串转换成一个PHP对象与JSON_Decode()。然后你可以直接操纵对象,迭代它等等。如果我能找到一个好例子,我会在这里发布它。 –