我正在使用XML,如:
[self.tableView beginUpdates];
[self.myDataArray insertObject:scannedItem atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath inSection:0]]
withRowAnimation:UITableViewRowAnimationRight];
[self.tableView endUpdates];
在Java代码中,我的课程<localMSZ>
<territories>
<codeOKTMO>str1</codeOKTMO>
<codeOKTMO>str2</codeOKTMO>
</territories>
</localMSZ>
有LocalMSZ
List
,如:
String
我不明白在这种情况下我应该如何发布注释?
答案 0 :(得分:0)
问题在于您的映射类:它缺少此所需的结构和注释。它应该适用于此:
import java.util.LinkedList;
import java.util.List;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import com.thoughtworks.xstream.annotations.XStreamImplicit;
import com.thoughtworks.xstream.converters.extended.ToAttributedValueConverter;
@XStreamAlias("localMSZ")
public class LocalMSZ {
private Territories territories = new Territories();
public Territories getTerritories() {
return territories;
}
public void setTerritories(Territories territories) {
this.territories = territories;
}
@XStreamAlias("codeOKTMO")
@XStreamConverter(value = ToAttributedValueConverter.class, strings = { "value" })
public static class Code {
private String value;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
@XStreamAlias("territories")
public static class Territories {
// This one maps the sequence of <codeOKTMO> tags
@XStreamImplicit
private List<Code> codes = new LinkedList<Code>();
public List<Code> getCodes() {
return codes;
}
public void setCodes(List<Code> codes) {
this.codes = codes;
}
}
}
当您编写主要方法来处理LocalMSZ的注释
时,请记住XStream xstream = new XStream();
xstream.processAnnotations(LocalMSZ.class);
...