简体   繁体   English

Velocity中的JSONObject

[英]JSONObject in Velocity

I have Java code that returns a JSONObject 我有返回JSONObject Java代码

I then retrieve it in velocity like this. 然后,我像这样快速检索它。
#set ($JSON = $patient.toJSON($displayedFields))

It displays fine, however there is one problem. 它显示正常,但是存在一个问题。 I cannot do this: 我不能做到这一点:

$JSON.put("test", "test")

Instead of adding ("test", "test") to $JSON it literally outputs $JSON.put("test", "test") 而不是在$ JSON上添加(“ test”,“ test”),而是直接输出$JSON.put("test", "test")

How can I add objects to JSONObject in velocity? 如何将对象快速添加到JSONObject

The answer is simple. 答案很简单。 (I just didn't pay enough attention) (我只是没有引起足够的重视)

The (test, test) does get put into the JSON. (test, test) 确实放入JSON中。 And to prevent $JSON.put("test", "test") from outputting itself, 为了防止$JSON.put("test", "test")输出自身,

#set ($discard = $JSON.put("test", "test"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM