当前位置:网站首页>[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}
边栏推荐
- 【DesignMode】组合模式(composite mode)
- anconda下载+添加清华+tensorflow 安装+No module named ‘tensorflow‘+KernelRestarter: restart failed,内核重启失败
- Spark AQE
- Mysql - CRUD
- NLP text processing: lemma [English] [put the deformation of various types of words into one form] [wet- > go; are- > be]
- MYSQL GROUP_ The concat function realizes the content merging of the same ID
- notepad++正则表达式替换字符串
- How to solve the problems caused by the import process of ecology9.0
- Global and Chinese markets of POM plastic gears 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese markets of universal milling machines 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

The relationship between FPGA internal hardware structure and code

电机的简介

多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)

Uniapp development, packaged as H5 and deployed to the server

OS i/o devices and device controllers

Classic CTF topic about FTP protocol

Notepad + + regular expression replace String

notepad++正則錶達式替換字符串

《强化学习周刊》第52期:Depth-CUPRL、DistSPECTRL & Double Deep Q-Network

Leetcode 450 deleting nodes in a binary search tree
随机推荐
从底层结构开始学习FPGA----FIFO IP核及其关键参数介绍
猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
如何解决ecology9.0执行导入流程流程产生的问题
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]
synchronized 和 ReentrantLock
2022.7.5-----leetcode. seven hundred and twenty-nine
[designmode] Decorator Pattern
Uniapp development, packaged as H5 and deployed to the server
【DesignMode】适配器模式(adapter pattern)
State mode design procedure: Heroes in the game can rest, defend, attack normally and attack skills according to different physical strength values.
时间戳的拓展及应用实例
剖面测量之提取剖面数据
Single source shortest path exercise (I)
Arduino六足机器人
Idea remotely submits spark tasks to the yarn cluster
Determinant learning notes (I)
【EI会议分享】2022年第三届智能制造与自动化前沿国际会议(CFIMA 2022)
Set data real-time update during MDK debug
数据分析思维分析方法和业务知识——分析方法(二)
Classic CTF topic about FTP protocol