简体   繁体   English

JSON自动转换为Java对象

[英]Automatic Conversion of JSON to Java Object

I was wondering if there is any way or library which allows the automatic conversion of json strings to java objects ? 我想知道是否有任何方法或库可以将json字符串自动转换为java对象?

ie similar functionality provided by Backbone for javascript. 即Backbone为javascript提供的类似功能。

I am fully aware you can do it step by step for each field using something like: 我完全知道,您可以使用类似的方法针对每个字段逐步执行此操作:

JSONObject json = new JSONObject(jsonString);
String body = json.get("body").toString;

However I have many json files to convert and manually typing out the code for ever object I need seems tedious. 但是我有很多json文件要转换,并为我需要的对象手动键入代码似乎很乏味。 Is there anyway to do it autonomously ? 反正有自主地做吗?

Ie provide an object template which can be populated regardless of it's fields ? 即提供一个对象模板,无论其字段如何,都可以填充?

大多数使用ajax的框架都允许您设置将为您执行此操作的配置。

MyClass a = Gson().fromJson(jsonString, MyClass.class)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM