[
{
"id": 1,
"name": "移动开发",
"alias": "mobile"
},
{
"id": 14,
"name": "Web前端",
"alias": "web"
},
{
"id": 15,
"name": "架构设计",
"alias": "enterprise"
},
{
"id": 16,
"name": "编程语言",
"alias": "code"
},
{
"id": 17,
"name": "互联网",
"alias": "www"
},
{
"id": 6,
"name": "数据库",
"alias": "database"
},
{
"id": 12,
"name": "系统运维",
"alias": "system"
},
{
"id": 2,
"name": "云计算",
"alias": "cloud"
},
{
"id": 3,
"name": "研发管理",
"alias": "software"
},
{
"id": 19,
"name": "特约专家",
"alias": "invite"
},
{
"id": 8,
"name": "行业名家",
"alias": "celebrity"
},
{
"id": 7,
"name": "综合",
"alias": "other"
},
{
"id": 20,
"name": "名誉专家",
"alias": "honour"
}
]
我解析以上json数据的时候,报出
java.lang.illegalStateException:Expected BEGIN_OBJECT but was BEGIN_ARRARY at line 1 column 2 path$
发现自己解析的时候,使用的是对象,而非数组。但是以上json是数组形式
package com.android.csdnclient.bean;
import com.google.gson.annotations.SerializedName;
/**
* 博客系统分类
*/
public class ChannelBean {
//分类id
@SerializedName("id")
private int id;
//分类名称
@SerializedName("name")
private String name;
//分类别名
@SerializedName("alias")
private String alias;
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package com.android.csdnclient.retrofit;
import com.android.csdnclient.bean.ChannelBean;
import java.util.List;
import retrofit2.http.GET;
import retrofit2.http.Query;
import rx.Observable;
/**
* 网络请求
*/
public interface CSDNService {
//获取博客系统分类
@GET("/blog/getchannel")
Observable> getChannel(@Query("client_id") String client_id);
}
Observable
这里必须使用对象容器来保存json数组。>