简体   繁体   中英

JSONObject in Velocity

I have Java code that returns a JSONObject

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")

How can I add objects to JSONObject in velocity?

The answer is simple. (I just didn't pay enough attention)

The (test, test) does get put into the JSON. And to prevent $JSON.put("test", "test") from outputting itself,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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