未解决的参考:Volley 中的 entrySet
Unresolved reference: entrySet in Volley
我使用 volley 库执行 POST 方法,但出现以下错误:Unresolved reference: entrySet.
我该如何解决这个问题?
这是我的代码:
科特林
@Throws(AuthFailureError::class)
override fun getBody(): ByteArray? {
val params = params
if (params != null && params.size > 0) {
return encoderParameters(params, paramsEncoding)
}
return null
}
fun encoderParameters(params: HashMap<String, String>, paramsEncoding: String): ByteArray {
val encodedParams = StringBuilder()
try {
for (entry in params.entrySet()) {
encodedParams.append(URLEncoder.encode(entry.key), paramsEncoding)
encodedParams . append ('=')
encodedParams . append (URLEncoder.encode(entry.value, paramsEncoding))
encodedParams . append ('&')
}
return encodedParams.toString().toByteArray(charset(paramsEncoding))
}catch (e: UnsupportedEncodingException){
throw RuntimeException("Encoding not supported: $paramsEncoding", e)
}
}
转换
for (entry in params.entrySet()) {
encodedParams.append(URLEncoder.encode(entry.key), paramsEncoding)
encodedParams . append ('=')
encodedParams . append (URLEncoder.encode(entry.value, paramsEncoding))
encodedParams . append ('&')
}
进入
for ((key, value) in params) {
encodedParams.append(URLEncoder.encode(key), paramsEncoding)
encodedParams . append ('=')
encodedParams . append (URLEncoder.encode(value, paramsEncoding))
encodedParams . append ('&')
}
应该可以。
我使用 volley 库执行 POST 方法,但出现以下错误:Unresolved reference: entrySet.
我该如何解决这个问题?
这是我的代码:
科特林
@Throws(AuthFailureError::class)
override fun getBody(): ByteArray? {
val params = params
if (params != null && params.size > 0) {
return encoderParameters(params, paramsEncoding)
}
return null
}
fun encoderParameters(params: HashMap<String, String>, paramsEncoding: String): ByteArray {
val encodedParams = StringBuilder()
try {
for (entry in params.entrySet()) {
encodedParams.append(URLEncoder.encode(entry.key), paramsEncoding)
encodedParams . append ('=')
encodedParams . append (URLEncoder.encode(entry.value, paramsEncoding))
encodedParams . append ('&')
}
return encodedParams.toString().toByteArray(charset(paramsEncoding))
}catch (e: UnsupportedEncodingException){
throw RuntimeException("Encoding not supported: $paramsEncoding", e)
}
}
转换
for (entry in params.entrySet()) {
encodedParams.append(URLEncoder.encode(entry.key), paramsEncoding)
encodedParams . append ('=')
encodedParams . append (URLEncoder.encode(entry.value, paramsEncoding))
encodedParams . append ('&')
}
进入
for ((key, value) in params) {
encodedParams.append(URLEncoder.encode(key), paramsEncoding)
encodedParams . append ('=')
encodedParams . append (URLEncoder.encode(value, paramsEncoding))
encodedParams . append ('&')
}
应该可以。