参数不匹配; SimpleXML [英] Parameter does not have a match; SimpleXML

查看:93
本文介绍了参数不匹配; SimpleXML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将retrofitSimpleXMLConverterFactory一起使用.

我总是得到

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

我不知道有什么问题. xml非常简单,我只需要success节点中的字符串.

And I have no idea what could be wrong. The xml is very simple and i only want the string from the success node.

xml:

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

ResponseInfo:

ResponseInfo:

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

我测试了Api调用,它返回了给定的xml.

Edit 1: I tested the Api call and it returns the given xml.

谢谢

推荐答案

所以最后,我设法解决了这个问题.

So finally, I managed myself to solve the problem.

问题是ResponseInfo类.在我将其更改为

The problem was the ResponseInfo class. After I changed it to

@Root(strict = false, name="response)
data class ResponseInfo @JvmOverloads constructor(
  @field:element(name = "success") var success: String = ""
)

一切正常.

您需要有一个空的构造函数,所有属性都必须是可变的(var),并且必须在@Element -Annotation前面附加field:. @JvmOverloads与默认值结合将为您以及所有其他构造函数变体创建空构造函数.

You need to have an empty constructor, all properties must be mutable (var) and you have to append field: in front of the @Element-Annotation. @JvmOverloads combined with default values will create the empty constructor for you as well as all other constructor variations.

这篇关于参数不匹配; SimpleXML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆