当前位置:网站首页>[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}
边栏推荐
- Multithreading and high concurrency (8) -- summarize AQS shared lock from countdownlatch (punch in for the third anniversary)
- 数据分析思维分析方法和业务知识——分析方法(三)
- Atcoder beginer contest 258 [competition record]
- Power Query数据格式的转换、拆分合并提取、删除重复项、删除错误、转置与反转、透视和逆透视
- About the slmgr command
- Set data real-time update during MDK debug
- OS i/o devices and device controllers
- Arduino hexapod robot
- Analysis of the combination of small program technology advantages and industrial Internet
- 建立时间和保持时间的模型分析
猜你喜欢
Go learning - dependency injection
如何制作自己的機器人
如何利用Flutter框架开发运行小程序
Idea remotely submits spark tasks to the yarn cluster
[EI conference sharing] the Third International Conference on intelligent manufacturing and automation frontier in 2022 (cfima 2022)
2022-02-13 work record -- PHP parsing rich text
Permission problem: source bash_ profile permission denied
notepad++正則錶達式替換字符串
Uniapp development, packaged as H5 and deployed to the server
How to use the flutter framework to develop and run small programs
随机推荐
7.5 simulation summary
Spark AQE
猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
PHP determines whether an array contains the value of another array
Recognize the small experiment of extracting and displaying Mel spectrum (observe the difference between different y_axis and x_axis)
Extension and application of timestamp
Power Query数据格式的转换、拆分合并提取、删除重复项、删除错误、转置与反转、透视和逆透视
Natural language processing (NLP) - third party Library (Toolkit):allenlp [library for building various NLP models; based on pytorch]
STM32按键消抖——入门状态机思维
Room cannot create an SQLite connection to verify the queries
Determinant learning notes (I)
[designmode] composite mode
[Chongqing Guangdong education] Chongqing Engineering Vocational and Technical College
Common API classes and exception systems
MDK debug时设置数据实时更新
Mysql - CRUD
Go learning - dependency injection
Basic introduction and source code analysis of webrtc threads
NLP generation model 2017: Why are those in transformer
详细页返回列表保留原来滚动条所在位置