[英]MYSQL JSON - how do I access nested JSON object that's indexed by numerical key?
I am trying to extract JSON document subtree that's indexed by numerical key.我正在尝试提取由数字键索引的 JSON 文档子树。
My JSON string:我的 JSON 字符串:
{
"pk": 20,
"tree": {
"100": {
"values": [
1, 2, 3
]
},
"abc" => 999
}
}
My code:我的代码:
$session = mysql_xdevapi\getSession("mysqlx://root:letmein@localhost");
$schema = $session->getSchema('test');
$coll = $schema->getCollection('myColl');
$expr = mysql_xdevapi\Expression('$.tree.*');
$result = $coll->find('$.pk=20')->fields(['$.tree[100]'])->execute();
Using '$.tree[100]'
results in使用
'$.tree[100]'
结果
[
'tree' => null
]
Using '$.tree.*'
results in使用
'$.tree.*'
结果
[
'tree' => [
0 => [
1, 2, 3
],
1 => 999
]
]
Using '$.tree.abc'
results in使用
'$.tree.abc'
结果
[
'tree' => [
'abc' => 999
]
]
So, '$.tree.abc'
works, but '$.tree[100]'
doesnt.因此,
'$.tree.abc'
有效,但'$.tree[100]'
。
Question .问题。 How can I access
values
key using '$.tree[100]' expression?如何使用“$.tree[100]”表达式访问
values
键?
Thanks!谢谢!
Thnx for report, following case: Thnx报告,以下情况:
$expr = mysql_xdevapi\\Expression('$.tree."100"'); $result = $coll->find('$.pk=25')->fields($expr)->execute();
will be supported in mysql_xdevapi v8.0.18 which is planned for Oct 14.将在计划于 10 月 14 日发布的 mysql_xdevapi v8.0.18 中得到支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.