当我使用JSON_EXTRACT funciton时,SQLITE中的JSON错误畸形

发布于 2025-01-26 05:52:50 字数 1019 浏览 4 评论 0原文

在我的sqllite表中,我的字段名为config,它以json文本的形式存储配置。.bellow

config> config> config> config字段中

{
"matRid": 1,
"holderType": 1,
"uomRid": 1,
"type": 502,
"stockConditionIndex": 800,
"serialRequired": 1,
"codepart": 1,
"allowEdit": 1
}

从此数据 中存储的示例数据波纹查询它引发畸形的JSON错误

 select json_extract(config, '$.codepart') as codepart FROM TableName 

测试JSON是否以正确的格式测试我是否已运行以下查询

select json_valid(config) from TableName

查询retuns 1,这证实了JSON以适当的格式

,以及我运行的是否运行查询直接像Bellow一样,使用字段的JSON值config查询将成功返回结果,

select json_extract('{
"matRid": 1,
"holderType": 1,
"uomRid": 1,
"type": 502,
"stockConditionIndex": 800,
"serialRequired": 1,
"codepart": 1,
"allowEdit": 1
}', '$.codepart') as codepart FROM TableName

如何通过使用列名来制作JSON_EXTRACT使用列名而不是JSON值DIRECLTY DIRECLTY在sqllite?

附加信息:SQLite版本3.35.5。

任何建议都会有所帮助..谢谢..

In my sqllite table i have field named config which stores configuration in the form of json text..

bellow is the sample data stored in config field

{
"matRid": 1,
"holderType": 1,
"uomRid": 1,
"type": 502,
"stockConditionIndex": 800,
"serialRequired": 1,
"codepart": 1,
"allowEdit": 1
}

from this data when I run the bellow query it throws malformed JSON error

 select json_extract(config, '$.codepart') as codepart FROM TableName 

to test whether json is in the correct format or not i have run the following query

select json_valid(config) from TableName

above query retuns 1, this confirms that json is in the proper format

and also if I run the query by directly like bellow, using the json value of the field config query will return result successfully,

select json_extract('{
"matRid": 1,
"holderType": 1,
"uomRid": 1,
"type": 502,
"stockConditionIndex": 800,
"serialRequired": 1,
"codepart": 1,
"allowEdit": 1
}', '$.codepart') as codepart FROM TableName

How to make json_extract work by using the column name instead of json value direclty in SqlLite?

additional info : SQLite Version 3.35.5.

any suggestions would be helpfull.. Thank you..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉墨 2025-02-02 05:52:50

该错误实际上是由json_extract用于排空记录(空字符串)的行 code> config> config

通过包括iif语句来解决的行。

SELECT json_extract(json(IIF(config <> '', config, NULL)), '$.codepart') from TableName

The error was actually produced by the json_extract for the rows with empty record (empty string) for the field config

resolved it by including the IIF statement

SELECT json_extract(json(IIF(config <> '', config, NULL)), '$.codepart') from TableName
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文