参数不匹配; SimpleXML的

我正在使用SimpleXMLConverterFactory进行retrofit

我总是得到一个

 ConstructorException: Parameter 'success' does not have a match in class ResponseInfo 

我不知道有什么可能是错的。 XML是非常简单的,我只想从success节点的字符串。

XML:

 <?xml version="1.0" encoding="UTF-8"?> <response> <success>LoremIpsum</success> </response> 

ResponseInfo:

 @Root(strict = false, name = "response") data class ResponseInfo(@Element(required = false, name = "success) var success: String) 

编辑1:我测试了Api调用,它返回给定的XML。

谢谢

最后,我设法解决了这个问题。

问题是ResponseInfo类。 我改变后

 @Root(strict = false, name="response) data class ResponseInfo(@field:element(name = "success") var success: String) { construcotr(): this("") } 

一切正常。

你需要有一个空的构造函数,所有的属性必须是可变的( var ),你必须在@Element -Annotation前添加field: