【问题标题】:Ruby Siren jsonquery红宝石警报器jsonquery
【发布时间】:2015-01-09 02:40:27
【问题描述】:

我的json内容存储在一个文件中:

{
    "vms": [
        {
            "component": "pgdb",
            "count": "1",
            "endpoints": "80:8080,5432:5432"
        },
        {
            "component": "mq",
            "count": "1",
            "endpoints": "80:8080,5672:5672,15672:15672"
        },
        {
            "component": "ucms",
            "count": "1",
            "endpoints": "80:80,8080:8080"
        },
        {
            "component": "wsgw",
            "count": "1",
            "endpoints": "8080:8080,9093:9093"
        }
    ]
}

in irb :

require 'json'
require 'Siren'

json = File.read('c:\\stack1.json')
irb(main):022:0> Siren.query "$.vms..[? @.component == ucms ]", json
=> []

我正在尝试起草一个查询,该查询将搜索组件名称并返回端点的值。 任何帮助/指针将不胜感激。

感谢

【问题讨论】:

    标签: ruby siren


    【解决方案1】:

    对于字符串匹配,您需要使用= 运算符,而不是==。另外读取的文件需要在查询前解析:

    json = Siren.parse File.read('c:\\stack1.json')
    Siren.query "$.vms..[? @.component = ucms ]", json
    

    【讨论】:

    • 感谢 Edu,这有帮助。抱歉,因为我没有足够的声誉,所以无法支持​​您的回答。
    猜你喜欢
    • 2011-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-09
    相关资源
    最近更新 更多