JSON Format Plugin
Introduction
The JSON Format plugin is a powerful tool for JSON data manipulation and conversion. It supports multiple IDEs, including IDEA, Android Studio, and DevEco Studio, making it a versatile addition to your development workflow.
Features
- JSON to JavaBean: Convert JSON data into a JavaBean class.
- JSON to Harmony .ets Model: Transform JSON data into a Harmony .ets file.
- JavaBean to Harmony .ets Model: Convert existing JavaBean classes into Harmony .ets files.
Version History
Here's a summary of the plugin's version updates and compatibility:
Plugin Version | IDEA Version | DevEco Version | Android Studio Version | Notes |
---|---|---|---|---|
v1.0.2 | 2023.3.1 | 5.0.3.403 | Android Studio Jellyfish 2023.3.1 | |
v1.0.3 | 2023.3.1 | 5.0.3.403 | Android Studio Jellyfish 2023.3.1 | |
v1.0.4-deveco | 2023.3.1 | 5.0.3.501 | Android Studio Jellyfish 2023.3.1 | Deprecated |
v1.0.5-deveco | 2023.3.1 | 5.0.3.502 | Android Studio Jellyfish 2023.3.1 | Supports DevEco marketplace download |
v1.0.6 | 2023.3.1 | 5.0.3.502 | Android Studio Jellyfish 2023.3.1 | Supports DevEco marketplace download |
Notes
- The plugin versions with the suffix "deveco" are specially designed for DevEco Studio. Please do not use them in IDEA or Android Studio.
- Starting from version v1.0.6, the plugin supports all three conversion formats and is compatible with IDEA, Android Studio, and DevEco Studio.
Installation
You can find the plugin for download at plugins.jetbrains.com/plugin/2493. For Harmony IDE, follow these steps to install the plugin:
- Open DevEco Studio and navigate to Settings > Plugins.
- Click on "Install Plugin from Disk."
- Locate the downloaded plugin file with a .jar extension and select it.
- Click OK to start the installation process.
- Once the installation is complete, restart your IDE.
Usage
Converting JSON to Harmony .ets Model
- Create a new class file, such as User.ets.
- Right-click in the editor and select Generate, then choose Json2ets. You can also use the shortcut keys Alt + Insert to quickly access the Json2ets option.
- Paste your JSON string into the dialog box, enter a class name that matches the file name, and select whether to generate a class or interface.
- Click OK to generate the corresponding .ets model.
Examples
Simple JSON
JSON:
{
"msg": "Success",
"code": 200
}
Generated Code:
export class User {
msg?: string;
code?: number;
}
Nested JSON
JSON:
{
"msg": "Success",
"code": 200,
"data": {
"username": "John Doe",
"password": "123456"
}
}
Generated Code:
export class User {
msg?: string;
code?: number;
data?: User.Data;
}
export namespace User {
export class Data {
username?: string;
password?: string;
}
}
JSON with List
JSON:
{
"msg": "Success",
"code": 200,
"data": [
{
"id": 12,
"name": "Senior Android Engineer",
"cname": " Toutiao",
"size": "Series D",
"salary": "40K-60K",
"username": "Kimi",
"title": "HR",
"page": "0"
},
{
"id": 13,
"name": "Mobile Architect",
"cname": "Yinhuan Games",
"size": "Series B",
"salary": "15K-20K",
"username": "Liu Li",
"title": "Personnel Manager",
"page": "0"
},
{
"id": 14,
"name": "Java Engineer",
"cname": "37 Entertainment",
"size": "Series D",
"salary": "25K-30K",
"username": "Reiki",
"title": "HR-M",
"page": "0"
},
{
"id": 16,
"name": "iOS Engineer",
"cname": "Yinhuan Games Technology",
"size": "Series D",
"salary": "15K-20K",
"username": "Ma Xiaoling",
"title": "Java Programmer",
"page": "0"
},
{
"id": 17,
"name": "Java Engineer",
"cname": "4399 Games Technology",
"size": "Series C",
"salary": "15K-20K",
"username": "Ma Xiaoling",
"title": "HR-M",
"page": "0"
}
]
}
Generated Code:
export class User {
msg?: string;
code?: number;
data?: User.Data[];
}
export namespace User {
export class Data {
id?: number;
name?: string;
cname?: string;
size?: string;
salary?: string;
username?: string;
title?: string;
page?: string;
}
}
Top comments (0)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.