有没有简单的方法
我可以使用JAXBContext,Marshaller等运行并查看XML.
JSON有什么例子吗?
我找到了.它类似于JAXB.
final JSONJAXBContext context = new JSONJAXBContext(...);
final JSONMarshaller marshaller = context.createJSONMarshaller();
marshaller.marshallToJSON(...);
final JSONUnmarshaller unmarshaller = context.createJSONUnmarshaller();
final T unmarshalled = unmarshaller.unmarshalJAXBElementFromJSON(
..., T.class).getValue();
Run Code Online (Sandbox Code Playgroud)
对于Maven
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
有可能的:
...
StringWriter writer = new StringWriter();
marshaller.marshallToJSON(objectToMarshall, writer)
logger.debug(writer.toString());
...
Run Code Online (Sandbox Code Playgroud)
您可以使用 anStringWriter来表示String编组的 JSON 输出。
| 归档时间: |
|
| 查看次数: |
2150 次 |
| 最近记录: |