我在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" }]

最佳答案

您可以将其转换为对象集合,然后在foreach中循环它们
并测试任何条件并移除任何物体
最后将其再次转换为json

关于mysql - 从mysql中的对象数组中删除json对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57057183/

10-09 06:47