我有一个名为 User 的表,其中包含名为 userDetails 的列。 userDetails 列具有 json 格式的数据,如下所示。
{
"id": "77",
"uid": "247",
"email": "abc@xyz.com",
}
如何查询此 json 对象中存在的“where uid = 247”。
最佳答案
如果列userDetails
是一个有效的 JSON 字符串,你可以使用函数 json_extract()
:
select *
from user
where json_extract(userDetails, '$.uid') = '247'
如果不能使用 SQLite 的 JSON1 扩展,可以通过处理 userDetails
来实现。作为普通字符串并使用运算符 LIKE
:select *
from user
where ',' || replace(replace(replace(userDetails, '{', ''), '}', ''), ' ', '') || ',' like '%,"uid":"' || '247' ||'",%'
替换 ?
带有您搜索的 id 的占位符,例如 '247'
.查看简化版 demo .
关于java - 从sqlite中的json搜索值 - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65103073/