我在mysql表中有一个列userinventory
,其中包含以下数据,我想删除json对象之一,其中“ sellFlag”:“ y”和“ product_id”:“ 1”
[{
"price": "250",
"category": "Furniture",
"sellFlag": "y",
"assetLink": "Furniture/Table",
"product_id": "1"
},
{
"price": "175",
"category": "Furniture",
"assetLink": "Furniture/IkeaStockholmCoffeeTableBlack",
"product_id": "31"
},
{
"price": "300",
"category": "Furniture",
"assetLink": "Furniture/ZanottaDamaSofaMultiseater",
"product_id": "29"
},
{
"price": "200",
"category": "Furniture",
"assetLink": "Furniture/RoundTable",
"product_id": "9"
}]
我已经尝试select JSON_SEARCH(userInventory,'all','y', NULL,'$[*].sellFlag') as uInvent FROM user_information WHERE user_id=50
给予结果"$[27].sellFlag"
,但我也需要为product_id添加条件
成功删除后,需要以下结果。
[{
"price": "175",
"category": "Furniture",
"assetLink": "Furniture/IkeaStockholmCoffeeTableBlack",
"product_id": "31"
},
{
"price": "300",
"category": "Furniture",
"assetLink": "Furniture/ZanottaDamaSofaMultiseater",
"product_id": "29"
},
{
"price": "200",
"category": "Furniture",
"assetLink": "Furniture/RoundTable",
"product_id": "9"
}]
答案 0 :(得分:0)
您可以将其转换为对象集合,然后将其循环到foreach
中
并测试任何条件并移除任何物体
最后将其再次转换为json