java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

本文详细介绍了Android中的Relative Layout布局,包括其用于设置视图相对位置的各种属性,如layout_toLeftOf、layout_alignParentBottom等,并提供了一个示例代码,展示了如何在布局中实现视图的居中、对齐等效果。
摘要由CSDN通过智能技术生成

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
    }
]

自己试试看就知道

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

彬sir哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值