在使用 Velocity(2.2 版)时,我注意到访问 json 数组 org.json.JSONArray
中的对象数量时可能会出现差异。
$arrayrefence.length()
的使用似乎在不同的系统上产生了结果。然而,当我尝试在如下所述的宏中使用它时,它似乎没有提供结果:
#macro(doSomething)
#if($arrayrefence.length() > 0)
#set($myVar = $arrayreference)
#else
$math.sum(…)
#end
#end
似乎没有评估 $arrayrefence.length()
。 if / else
不起作用。如何在 if / else
语句中检查 json 数组的长度?
How to access/get the size of an array/collection in velocity templates? 中描述的解决方案不提供解决方案。