当前位置:网站首页>[groovy] JSON serialization (jsonbuilder builder | generates JSON string with root node name | generates JSON string without root node name)
[groovy] JSON serialization (jsonbuilder builder | generates JSON string with root node name | generates JSON string without root node name)
2022-07-06 00:35:00 【Programmer community】
One 、json generator
First , establish json generator .
// json generator def jsonBuilder = new JsonBuilder()
then , If you generate a with the root node name json character string , Need to use jsonBuilder. Root node name = { Closure }
Format code , Generate json character string ;
// Generate {"student":{"name":"Tom","age":18}}// among .student Represents the name of the root node , This is not a method name jsonBuilder.student{
name "Tom" age 18}
Generated by the above code json String is
{
"student":{
"name":"Tom","age":18}}
Last , If you want to generate
{
"name":"Tom","age":18}
Style string , Then use
// Generate {"name":"Tom","age":18}jsonBuilder{
name "Tom" age 18}
The code can be , Get rid of . Root node name
, Use it directly jsonBuilder{ Closure }
Generate json character string ;
Two 、 Code example
json Generator code example :
import groovy.json.JsonBuilder// json generator def jsonBuilder = new JsonBuilder()// Generate {"student":{"name":"Tom","age":18}}// among .student Represents the name of the root node , This is not a method name jsonBuilder.student{
name "Tom" age 18}println jsonBuilder// Generate {"name":"Tom","age":18}jsonBuilder{
name "Tom" age 18}println jsonBuilder
Execution results :
{
"student":{
"name":"Tom","age":18}}{
"name":"Tom","age":18}
边栏推荐
- The relationship between FPGA internal hardware structure and code
- 时间戳的拓展及应用实例
- LeetCode 6004. Get operands of 0
- MDK debug时设置数据实时更新
- [simple implementation of file IO]
- About the slmgr command
- Data analysis thinking analysis methods and business knowledge -- analysis methods (II)
- 多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
- Browser local storage
- MySql——CRUD
猜你喜欢
MySql——CRUD
建立时间和保持时间的模型分析
Arduino六足机器人
Go learning --- structure to map[string]interface{}
Leetcode 450 deleting nodes in a binary search tree
Choose to pay tribute to the spirit behind continuous struggle -- Dialogue will values [Issue 4]
Room cannot create an SQLite connection to verify the queries
Comment faire votre propre robot
MIT博士论文 | 使用神经符号学习的鲁棒可靠智能系统
XML Configuration File
随机推荐
MySQL functions
【EI会议分享】2022年第三届智能制造与自动化前沿国际会议(CFIMA 2022)
Notepad++ regular expression replacement string
Classic CTF topic about FTP protocol
Uniapp development, packaged as H5 and deployed to the server
多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
Spark-SQL UDF函数
Search (DFS and BFS)
NLP generation model 2017: Why are those in transformer
Atcoder beginer contest 254 [VP record]
Atcoder beginer contest 258 [competition record]
State mode design procedure: Heroes in the game can rest, defend, attack normally and attack skills according to different physical strength values.
NLP basic task word segmentation third party Library: ICTCLAS [the third party library with the highest accuracy of Chinese word segmentation] [Chinese Academy of Sciences] [charge]
Spark DF adds a column
STM32 key chattering elimination - entry state machine thinking
Classical concurrency problem: the dining problem of philosophers
小程序技术优势与产业互联网相结合的分析
Location based mobile terminal network video exploration app system documents + foreign language translation and original text + guidance records (8 weeks) + PPT + review + project source code
Go learning - dependency injection
Spark SQL空值Null,NaN判断和处理