Json of this kind comes to postman
{
"message": "The given data was invalid.",
"errors": {
"phone": [
"The phone has already been taken."
]
}
When prompted in the code, the error "java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $" appears
Here are my models
data class Response(
@SerializedName(MESSAGE)
val reason: String,
@SerializedName(ERRORS)
val errors: Errors? = null
) {
companion object {
private const val MESSAGE = "message"
private const val ERRORS = "errors" }
}
data class Errors(
@SerializedName("phone")
val phone: List<String?>? = null
)
When I add a phone number that is not already on my account, I receive such a json
{
"message": "Successfully added mobile!"
}
Create a two files Response.kt and Errors.kt Inside Response.kt
import com.google.gson.annotations.SerializedName
data class Response(
@SerializedName("errors")
val errors: Errors?,
@SerializedName("message")
val message: String?
)
Inside Errors.kt
import com.google.gson.annotations.SerializedName
data class Errors(
@SerializedName("phone")
val phone: List<String?>?
)
If Errors are not received in JSON means Please check null. If not working Please your checkresponse format.Hope it will help you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.