android studio kotlin 网络库Retrofit 编译的报错提示:java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
编译:java.lang.IllegalStateException:应为BEGIN_ARRAY,但在第1行第2列路径中为BEGIN_OBJECT$
解决问题:
我写的实体类:
class App(
val avatar_url: String,
val bio: Any,
val blog: String,
val company: Any,
val created_at: String,
val email: Any,
val events_url: String,
val followers: Int,
val followers_url: String,
val following: Int,
val following_url: String,
val gists_url: String,
val gravatar_id: String,
val hireable: Any,
val html_url: String,
val id: Int,
val location: Any,
val login: String,
val name: Any,
val node_id: String,
val organizations_url: String,
val public_gists: Int,
val public_repos: Int,
val received_events_url: String,
val repos_url: String,
val site_admin: Boolean,
val starred_url: String,
val subscriptions_url: String,
val twitter_username: Any,
val type: String,
val updated_at: String,
val url: String
)
json:
{
"login": "xinyitiandi",
"id": 11599121,
"node_id": "MDQ6VXNlcjExNTk5MTIx",
"avatar_url": "https://avatars.githubusercontent.com/u/11599121?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/xinyitiandi",
"html_url": "https://github.com/xinyitiandi",
"followers_url": "https://api.github.com/users/xinyitiandi/followers",
"following_url": "https://api.github.com/users/xinyitiandi/following{/other_user}",
"gists_url": "https://api.github.com/users/xinyitiandi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/xinyitiandi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/xinyitiandi/subscriptions",
"organizations_url": "https://api.github.com/users/xinyitiandi/orgs",
"repos_url": "https://api.github.com/users/xinyitiandi/repos",
"events_url": "https://api.github.com/users/xinyitiandi/events{/privacy}",
"received_events_url": "https://api.github.com/users/xinyitiandi/received_events",
"type": "User",
"site_admin": false,
"name": null,
"company": null,
"blog": "",
"location": null,
"email": null,
"hireable": null,
"bio": null,
"twitter_username": null,
"public_repos": 13,
"public_gists": 0,
"followers": 0,
"following": 0,
"created_at": "2015-03-22T15:51:50Z",
"updated_at": "2022-10-19T05:55:47Z"
}
json这是一个花括号里只有数据的,里面没有还有花括号和其他的,可以写代码:
比如:Callback<App>
怎么把Callback<App>改为Callback<List<App>>
List的实体类App.kt,可能是:
[
{
"code":"101010200",
"label":"北京",
"value":1
},
{
"code":"101020200",
"label":"上海",
"value":2
},
{
"code":"101030200",
"label":"天津",
"value":3
},
{
"code":"101040200",
"label":"重庆",
"value":4
}
]
自己试试看就知道