【问题标题】:g1ant: jsonpath with method length() not implementedg1ant:未实现方法长度()的jsonpath
【发布时间】:2020-03-15 05:00:32
【问题描述】:

我在获取数组的大小项时遇到问题。 jsonPath "length()" 的函数未在 g1ant 中实现,因为抛出异常 "Array index expected"。 以下是用于测试的 g1ant 脚本示例。

addon core version 4.103.0.0
addon language version 4.104.0.0
♥jsonImage = ⟦json⟧‴{ "book" : [ { "name" : "Bambi"} , { "name" : "Cinderella" } ] }‴
♥aaa = ♥jsonImage⟦$.book.length()⟧
dialog ♥aaa

还有其他与数组长度相关的解决方案吗?

【问题讨论】:

    标签: automation robotics rpa g1ant


    【解决方案1】:

    无法以您尝试的方式获取 json 数组元素的数量。 G1ANT 正在使用 Newtonsoft.Json 库来选择 json 令牌,它们不允许像 .length() 这样的表达式,您可以阅读 here

    以下是解决此问题的方法。

    ♥jsonImage = ⟦json⟧‴{ "book" : [ { "name" : "Bambi"} , { "name" : "Cinderella" } ] }‴
    
    ♥jsonArrLength = 0
    ♥hasExceptionOccurred = false
    
    while ⊂!♥hasExceptionOccurred⊃
        try errorcall NoMoreElements
            ♥test = ♥jsonImage⟦book[♥jsonArrLength]⟧
            ♥jsonArrLength = ♥jsonArrLength + 1
        end try
    end while
    
    dialog ♥jsonArrLength
    
    procedure NoMoreElements
        ♥hasExceptionOccurred = true
    end procedure
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-16
      • 1970-01-01
      • 2014-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-30
      • 2010-09-21
      相关资源
      最近更新 更多