简体   繁体   中英

SQLite Query that parses JSON string in a column

I have a SQLite database built with ROOM persistence to store Users data. One of the fields in the User object is a MAP which is stored in the table as Json String

column name: "user_status"

{"user1":1, "user2":0, "user3":2, ....}

Now I want to query through this JSON string to filter the list of users according to their status

Something like:

SELECT * FROM users WHERE status.user1 = 1

How can I manage that?

I managed to work around by using LIKE and parsing the JSON data as String

SELECT * FROM users WHERE status LIKE '%'||:userId||'\":1%' LIMIT 1

I know it might not be the best option, but works for now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM