gpt4 book ai didi

java - 如何在 Eclipse 中导出或保存检查的对象结构?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:29:58 27 4
gpt4 key购买 nike

有没有办法保存/导出(也需要能够稍后查看)检查的对象结构?

sample inspection window in eclipse

可能导出为 XML 或 JSON 结构?

最佳答案

您可以使用 xstream ,例如

Java 对象:

 public class Person {
private String firstname;
private String lastname;
private PhoneNumber phone;
private PhoneNumber fax;
// ... constructors and methods
}

public class PhoneNumber {
private int code;
private String number;
// ... constructors and methods
}'

简单实例化 XStream 类:

XStream xstream = new XStream();

创建一个 Person 实例并填充其字段:

Person joe = new Person("Joe", "Walnes");
joe.setPhone(new PhoneNumber(123, "1234-456"));
joe.setFax(new PhoneNumber(123, "9999-999"));

将其转换为 XML

String xml = xstream.toXML(joe);'

结果

<person>
<firstname>Joe</firstname>
<lastname>Walnes</lastname>
<phone>
<code>123</code>
<number>1234-456</number>
</phone>
<fax>
<code>123</code>
<number>9999-999</number>
</fax>
</person>

关于java - 如何在 Eclipse 中导出或保存检查的对象结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12000462/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com