1
0
mirror of https://github.com/Snailclimb/JavaGuide synced 2025-06-16 18:10:13 +08:00

33 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: GsonFormatJSON转对象
category: IDEA指南
tag:
- IDEA
- IDEA插件
---
GsonFormat 这个插件可以根据Gson库使用的要求,将JSONObject格式的String 解析成实体类。
> 说明2021.x 版本以上的 IDEA 可以使用GsonFormatPlus
这个插件使用起来非常简单,我们新建一个类,然后在类中使用快捷键 `option + s`(Mac)或`alt + s` (win)调出操作窗口(**必须在类中使用快捷键才有效**),如下图所示。
![](./pictures/GsonFormat2.gif)
这个插件是一个国人几年前写的不过已经很久没有更新了可能会因为IDEA的版本问题有一些小Bug。而且这个插件无法将JSON转换为Kotlin这个其实无关痛痒IDEA自带的就有Java转Kotlin的功能
![](./pictures/GsonFormat1.png)
另外一个与之相似的插件是 **RoboPOJOGenerator** ,这个插件的更新频率比较快。
`File-> new -> Generate POJO from JSON`
![](./pictures/RoboPOJOGenerator1.png)
然后将JSON格式的数据粘贴进去之后配置相关属性之后选择“*Generate*”
![](./pictures/RoboPOJOGenerator2.png)