php - MYSQL JSON - 如何访问由数字键索引的嵌套 JSON 对象?
问题描述
我正在尝试提取由数字键索引的 JSON 文档子树。
我的 JSON 字符串:
{
"pk": 20,
"tree": {
"100": {
"values": [
1, 2, 3
]
},
"abc" => 999
}
}
我的代码:
$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();
使用'$.tree[100]'
结果
[
'tree' => null
]
使用'$.tree.*'
结果
[
'tree' => [
0 => [
1, 2, 3
],
1 => 999
]
]
使用'$.tree.abc'
结果
[
'tree' => [
'abc' => 999
]
]
所以,'$.tree.abc'
有效,但'$.tree[100]'
没有。
问题。如何values
使用 '$.tree[100]' 表达式访问密钥?
谢谢!
解决方案
Thnx 报告,以下情况:
$expr = mysql_xdevapi\Expression('$.tree."100"'); $result = $coll->find('$.pk=25')->fields($expr)->execute();
计划于 10 月 14 日推出的 mysql_xdevapi v8.0.18 将支持。
推荐阅读
- sql - SQL Server 系统如何检查重复项?
- spring - 是否可以在 Spring Boot 应用程序启动期间从 Web 服务加载属性?
- android - handler.postDelayed() 未执行
- python - Python egg 创建忽略非 .py 文件
- sql-server - 将 laravel 5.6 连接到 SQL Server Express
- angular - '找不到管道截断'
- file-io - 使用多数据类型输入损坏的 Fortran95 读取
- python - Xlsxwriter 根据 if 语句更改格式颜色
- vue.js - 是否可以使用 vuejs 在 web-worker 内部进行 ajax 调用
- sql - Saxon SQL 扩展不适用于 Saxon 9.8.0.8 PE 或 EE 上的 XSLT