json生成java对象_使用在线工具jsonschema2pojo根据json生成java对象

如果你还在自己手动写model对象,那你就out了。

场景:使用retrofit请求github的api,要使返回的数据自动解析到java对象中你必须准备好一个和json完全对应的java对象。而github的一个Repository有很多字段,如这个请求:

你可以直接打开这个链接查看返回的json数据。可以看到里面有很多数据项,如果我们手动写这个java对象将非常耗费时间。

所幸现在有了转换的工具。

jsonschema2pojo

jsonschema2pojo  是一个根据json转换成java对象的开源项目,只要把你的json字符串复制到相应的输入框中就能自动将其转换成java对象。它的强大之处在于,能解析列表式的json数据,把嵌套在内层的对象也解析出来。

先以上面的api请求为例,得到的json如下,这是一个单一的Repository数据:{

"id": 1296269,

"name": "Hello-World",

"full_name": "octocat/Hello-World",

"owner": {

"login": "octocat",

"id": 583231,

"avatar_url": "https://avatars.githubusercontent.com/u/583231?v=3",

"gravatar_id": "",

"url": "https://api.github.com/users/octocat",

"html_url": "https://github.com/octocat",

"followers_url": "https://api.github.com/users/octocat/followers",

"following_url": "https://api.github.com/users/octocat/following{/other_user}",

"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",

"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",

"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",

"organizations_url": "https://api.github.com/users/octocat/orgs",

"repos_url": "https://api.github.com/users/octocat/repos",

"events_url": "https://api.github.com/users/octocat/events{/privacy}",

"received_events_url": "https://api.github.com/users/octocat/received_events",

"type": "User",

"site_admin"

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值