请教一下脚本大佬,问了几个AI都没解决
[*][[*]{
[*] "fqn": "24ska01-sgp.ram-32g-noecc-2133.softraid-1x480ssd",
[*] "memory": "ram-32g-noecc-2133",
[*] "planCode": "24ska01-sgp",
[*] "server": "24ska01",
[*] "storage": "softraid-1x480ssd",
[*] "datacenters": [
[*] {
[*] "availability": "1H-high",
[*] "datacenter": "sgp"
[*] }
[*] ]
[*]},
[*]{
[*] "fqn": "24ska01-syd.ram-32g-noecc-2133.softraid-1x480ssd",
[*] "memory": "ram-32g-noecc-2133",
[*] "planCode": "24ska01-syd",
[*] "server": "24ska01",
[*] "storage": "softraid-1x480ssd",
[*] "datacenters": [
[*] {
[*] "availability": "1H-high",
[*] "datacenter": "syd"
[*] }
[*] ]
[*]},
[*]{
[*] "fqn": "24ska01.ram-64g-noecc-2133.softraid-1x480ssd",
[*] "memory": "ram-64g-noecc-2133",
[*] "planCode": "24ska01",
[*] "server": "24ska01",
[*] "storage": "softraid-1x480ssd",
[*] "datacenters": [
[*] {
[*] "availability": "unavailable",
[*] "datacenter": "bhs"
[*] },
[*] {
[*] "availability": "unavailable",
[*] "datacenter": "fra"
[*] },
[*] {
[*] "availability": "unavailable",
[*] "datacenter": "gra"
[*] },
[*] {
[*] "availability": "unavailable",
[*] "datacenter": "lon"
[*] },
[*] {
[*] "availability": "unavailable",
[*] "datacenter": "rbx"
[*] },
[*] {
[*] "availability": "unavailable",
[*] "datacenter": "sbg"
[*] },
[*] {
[*] "availability": "unavailable",
[*] "datacenter": "waw"
[*] }
[*] ]
[*]}
[*]]复制代码
这是ks-a的api结果,现在想要用一段jsonata语句只查询"fqn": "24ska01.ram-64g-noecc-2133.softraid-1x480ssd"这个数组里的datacenter availability不等于unavailable的结果。问了几个AI,百度的,微软的,阿里的都没解决,最后还是来问问万能的mjj吧。 js里面,用filter,把fqn是的拿出来24ska01.ram-64g-noecc-2133.softraid-1x480ssd,然后再用一下filter,过滤里面的datacenters数组
static/image/smiley/default/lol.gif
不教你 讓你搶不到
static/image/smiley/default/lol.gif
本帖最后由 我是老王 于 2024-11-17 21:51 编辑
[*]要使用 JSONata 语句从给定的 JSON 数据中查询 `fqn` 为 `24ska01.ram-64g-noecc-2133.softraid-1x480ssd` 且 `datacenter` 的 `availability` 不等于 `unavailable` 的结果,可以使用以下 JSONata 表达式:
[*]
[*]```jsonata
[*]$.datacenters^(fqn = "24ska01.ram-64g-noecc-2133.softraid-1x480ssd").datacenters
[*]```
[*]
[*]这段 JSONata 表达式的工作原理如下:
[*]
[*]1. `$.datacenters`:获取所有 `availability` 不等于 `unavailable` 的 `datacenters`。
[*]2. `^(fqn = "24ska01.ram-64g-noecc-2133.softraid-1x480ssd")`:过滤出 `fqn` 为 `"24ska01.ram-64g-noecc-2133.softraid-1x480ssd"` 的对象。
[*]3. `.datacenters`:再次从该对象中选择 `availability` 不等于 `unavailable` 的 `datacenters`。
[*]
[*]这将返回你所请求的符合条件的 `datacenter` 列表。复制代码 上面的都用过了,返回的结果都不对。
页:
[1]