更新时间:2022-04-30 05:20:02
而不是手动解析JSON
字符串,请尝试使用Google的GSON
库,该库可用于将JSON
字符串转换为等效的Java目的.
Instead of parsing the JSON
string manually, try using the Google's GSON
library that can be used to convert a JSON
string into an equivalent Java object.
使用jsonschema2pojo从JSON
字符串自动生成所需的POJO(Java)类.
Use jsonschema2pojo to auto-generate the POJO (Java) classes you need from your JSON
string.
步骤:
app/build.gradle
文件中添加以下行来GSON
库:dependencies { compile 'com.google.code.gson:gson:2.4' }
JSON
字符串复制并粘贴到输出框中.JSON
.JSON
字符串,请使用以下代码:Example example = new Gson().fromJson(json, Example.class);
GSON
library by adding the following line to the app/build.gradle
file: dependencies { compile 'com.google.code.gson:gson:2.4' }
JSON
string into the output box.JSON
for Source type.JSON
string use the following code: Example example = new Gson().fromJson(json, Example.class);