gpt4 book ai didi

android - 使用 SimpleXML 反序列化 XML 时遇到问题

转载 作者:行者123 更新时间:2023-11-30 03:34:50 25 4
gpt4 key购买 nike

我的类(class)被注释为

@Root
public class Geonames {
@Path("intersection/street1")
@Element
public String street1;

@Path("intersection/highway1")
@Element
public String highway1;

@Path("intersection/street2")
@Element
public String street2;

@Path("intersection/highway2")
@Element
public String highway2;

@Path("intersection/lat")
@Element
public String lat;

@Path("intersection/lng")
@Element
public String lng;

@Path("intersection/distance")
@Element
public String distance;
}

XML 是这样的:

<geonames>
<intersection>
<street1>11th Street</street1>
<highway1>residential</highway1>
<street2>Campbell Street</street2>
<highway2>unclassified</highway2>
<lat>37.8098123</lat>
<lng>-122.2969874</lng>
<distance>0.07</distance>
</intersection>
</geonames>

但是我得到了错误:

05-26 23:46:46.511: E//RequestProcessor.java:250(23618): Caused by:
org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy
@org.simpleframework.xml.Element(data=false, name=, required=true, type=void) on field
'street1' public java.lang.String com.mosier.securityapp.geonames.Geonames.street1 for
class com.mosier.securityapp.geonames.Geonames at line 4

这似乎表明 street1 没有值,但当然有。我的注释或类必须设置错误,但我对此太陌生了,看不出发生了什么。有没有我忽略的简单解决方法?

最佳答案

试试这个

@Root
public class Geonames {
@Path("intersection")
@Element
public String street1;

@Path("intersection")
@Element
public String highway1;

@Path("intersection")
@Element
public String street2;

@Path("intersection")
@Element
public String highway2;

@Path("intersection")
@Element
public String lat;

@Path("intersection")
@Element
public String lng;

@Path("intersection")
@Element
public String distance;
}

关于android - 使用 SimpleXML 反序列化 XML 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16767754/

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