我有一个 JSON 数字数组,例如 [16, 9, 11, 22, 23, 12]。我想获取数组中数字的索引。例如我说我想要索引 9,它应该返回 1。
我尝试在 MySQL 中使用下面提到的查询,但得到空值。
SELECT JSON_SEARCH(CAST('[16, 9, 11, 22, 23, 12]' AS JSON),'one',9)
Run Code Online (Sandbox Code Playgroud)
你们有解决办法吗?
我有这样的JSON:
{
"dcsId": "1184001100000000517",
"marketCode": "US",
"languageCode": "en-US",
"profile": {
"base": {
"username": "arunima27",
"activeInd": "R",
"phone": [
{
"activeInd": "Y",
"type": "mobile",
"primaryInd": "Y",
"number": "2234566788"
},
{
"activeInd": "N",
"type": "mobile",
"primaryInd": "N",
"number": ""
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
从这个输入JSON我们需要提取payload.profile.base.phone.number,其中payload.profile.base.phone.type =="mobile"和payload.profile.base.phone.activeInd =="Y".实际上,我们需要循环遍历JSON数组(payload.profile.base.*phone)并仅获取活动且类别/类型为mobile的电话号码.
我们需要如下输出:
{
"dcsId": "1184001100000000517",
"marketCode": "US",
"languageCode": "en-US",
"username" : "arunima27",
"phoneNumber" : "2234566788"
}
Run Code Online (Sandbox Code Playgroud)
我们在为"phoneNumber"输出变量进行此转换时遇到问题.