【发布时间】:2014-08-10 22:42:45
【问题描述】:
我需要将 POJO 转换为 JSONObject (org.json.JSONObject)
我知道如何将其转换为文件:
ObjectMapper mapper = new ObjectMapper();
try {
mapper.writeValue(new File(file.toString()), registrationData);
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
但我这次不想要文件。
【问题讨论】:
-
它有很多库:Jackson、Jettison。您还可以将 JAXB 与 MOXy 一起使用。
标签: java android json type-conversion jsonobject