JSON转JavaBean工具


点此查看V1.4更新及下载

点此查看并下载V1.3更新

点此查看并下载V1.2更新

V1.1下载地址

项目效果图

Alt Text

使用说明

  1. 填写包名
  2. 填写JavaBean的类名
  3. 选择保存的路径,默认保存按包名+类名的目录结构保存在我的文档,建议选择到项目src目录下面。
  4. 如果从网络获取json,填写jsonUrl,比如:http://enjoycode.info/uploads/test.json
  5. 如果json是本地的直接拷贝到json内容中即可
  6. 可选项:序列化,toString,无参构造(fastjson要求必须有),有参构造
  7. 点击生成

json文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
"fullname": "Sean Kelly",
"org": "SK Consulting",
"emailaddrs": [
{"type": "work", "value": "kelly@seankelly.biz"},
{"type": "home", "pref": 1, "value": "kelly@seankelly.tv"}
],

"telephones": [
{"type": "work", "pref": 1, "value": "+1 214 555 1212"},
{"type": "fax", "value": "+1 214 555 1213"},
{"type": "mobile", "value": "+1 214 555 1214"}
],

"addresses": [
{"type": "work", "format": "us",
"value": "1234 Main StnSpringfield, TX 78080-1216"},
{"type": "home", "format": "us",
"value": "5678 Main StnSpringfield, TX 78080-1316"}
],

"urls": [
{"type": "work", "value": "http://seankelly.biz/"},
{"type": "home", "value": "http://seankelly.tv/"}
]
}

解析后文件内容:

ExampleBean.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.snscity;

import java.io.Serializable;

public class ExampleBean implements Serializable{
private static final long serialVersionUID = 1471424463L;
private Urls urls;
private Emailaddrs emailaddrs;
private String org;
private String fullname;
private Telephones telephones;
private Addresses addresses;

public Urls getUrls() {
return this.urls;
}

public void setUrls(Urls urls) {
this.urls = urls;
}

public Emailaddrs getEmailaddrs() {
return this.emailaddrs;
}

public void setEmailaddrs(Emailaddrs emailaddrs) {
this.emailaddrs = emailaddrs;
}

public String getOrg() {
return this.org;
}

public void setOrg(String org) {
this.org = org;
}

public String getFullname() {
return this.fullname;
}

public void setFullname(String fullname) {
this.fullname = fullname;
}

public Telephones getTelephones() {
return this.telephones;
}

public void setTelephones(Telephones telephones) {
this.telephones = telephones;
}

public Addresses getAddresses() {
return this.addresses;
}

public void setAddresses(Addresses addresses) {
this.addresses = addresses;
}

public ExampleBean() {}

public ExampleBean(Urls urls, Emailaddrs emailaddrs, String org, String fullname, Telephones telephones, Addresses addresses){
super();
this.urls = urls;
this.emailaddrs = emailaddrs;
this.org = org;
this.fullname = fullname;
this.telephones = telephones;
this.addresses = addresses;
}

public String toString() {
return "ExampleBean [urls = " + urls + ", emailaddrs = " + emailaddrs + ", org = " + org + ", fullname = " + fullname + ", telephones = " + telephones + ", addresses = " + addresses + "]";
}
}

Emailaddrs.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.snscity;

import java.io.Serializable;

public class Emailaddrs implements Serializable{
private static final long serialVersionUID = 1201464670L;
private String value;
private String type;

public String getValue() {
return this.value;
}

public void setValue(String value) {
this.value = value;
}

public String getType() {
return this.type;
}

public void setType(String type) {
this.type = type;
}

public Emailaddrs() {}

public Emailaddrs(String value, String type){
super();
this.value = value;
this.type = type;
}

public String toString() {
return "ExampleBean [value = " + value + ", type = " + type + "]";
}
}

Telephones.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.snscity;

import java.io.Serializable;

public class Telephones implements Serializable{
private static final long serialVersionUID = 1201464670L;
private String value;
private String type;
private String pref;

public String getValue() {
return this.value;
}

public void setValue(String value) {
this.value = value;
}

public String getType() {
return this.type;
}

public void setType(String type) {
this.type = type;
}

public String getPref() {
return this.pref;
}

public void setPref(String pref) {
this.pref = pref;
}

public Telephones() {}

public Telephones(String value, String type, String pref){
super();
this.value = value;
this.type = type;
this.pref = pref;
}

public String toString() {
return "ExampleBean [value = " + value + ", type = " + type + ", pref = " + pref + "]";
}
}

Addresses.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.snscity;

import java.io.Serializable;

public class Addresses implements Serializable{
private static final long serialVersionUID = 1471424463L;
private String value;
private String format;
private String type;

public String getValue() {
return this.value;
}

public void setValue(String value) {
this.value = value;
}

public String getFormat() {
return this.format;
}

public void setFormat(String format) {
this.format = format;
}

public String getType() {
return this.type;
}

public void setType(String type) {
this.type = type;
}

public Addresses() {}

public Addresses(String value, String format, String type){
super();
this.value = value;
this.format = format;
this.type = type;
}

public String toString() {
return "ExampleBean [value = " + value + ", format = " + format + ", type = " + type + "]";
}
}

Urls.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.snscity;

import java.io.Serializable;

public class Urls implements Serializable{
private static final long serialVersionUID = 1077961738L;
private String value;
private String type;

public String getValue() {
return this.value;
}

public void setValue(String value) {
this.value = value;
}

public String getType() {
return this.type;
}

public void setType(String type) {
this.type = type;
}

public Urls() {}

public Urls(String value, String type){
super();
this.value = value;
this.type = type;
}

public String toString() {
return "ExampleBean [value = " + value + ", type = " + type + "]";
}
}

文章目录
  1. 1. 项目效果图
  2. 2. 使用说明
  3. 3. json文件:
  4. 4. 解析后文件内容: