当前位置:网站首页>[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 jsonBuilderExecution results :
{
"student":{
"name":"Tom","age":18}}{
"name":"Tom","age":18}
边栏推荐
- The global and Chinese markets of dial indicator calipers 2022-2028: Research Report on technology, participants, trends, market size and share
- Codeforces round 804 (Div. 2) [competition record]
- 图解网络:TCP三次握手背后的原理,为啥两次握手不可以?
- Data analysis thinking analysis methods and business knowledge -- analysis methods (II)
- The relationship between FPGA internal hardware structure and code
- Gd32f4xx UIP protocol stack migration record
- Choose to pay tribute to the spirit behind continuous struggle -- Dialogue will values [Issue 4]
- Single source shortest path exercise (I)
- [designmode] adapter pattern
- 剖面测量之提取剖面数据
猜你喜欢

MySql——CRUD

Arduino hexapod robot

Gavin teacher's perception of transformer live class - rasa project actual combat e-commerce retail customer service intelligent business dialogue robot system behavior analysis and project summary (4

anconda下载+添加清华+tensorflow 安装+No module named ‘tensorflow‘+KernelRestarter: restart failed,内核重启失败

Extension and application of timestamp

关于slmgr命令的那些事

Knowledge about the memory size occupied by the structure

Opencv classic 100 questions

Determinant learning notes (I)

Key structure of ffmpeg -- AVCodecContext
随机推荐
Spark SQL UDF function
如何利用Flutter框架开发运行小程序
Knowledge about the memory size occupied by the structure
如何制作自己的機器人
How to use the flutter framework to develop and run small programs
Folding and sinking sand -- weekly record of ETF
Permission problem: source bash_ profile permission denied
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
图解网络:TCP三次握手背后的原理,为啥两次握手不可以?
Natural language processing (NLP) - third party Library (Toolkit):allenlp [library for building various NLP models; based on pytorch]
NLP generation model 2017: Why are those in transformer
STM32按键消抖——入门状态机思维
Global and Chinese markets of universal milling machines 2022-2028: Research Report on technology, participants, trends, market size and share
Search (DFS and BFS)
Solve the problem of reading Chinese garbled code in sqlserver connection database
孤勇者
《编程之美》读书笔记
多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
Spark SQL空值Null,NaN判断和处理
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]