[
{
"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"
}
]
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
我解析以上json数据的时候,报出
java.lang.illegalStateException:Expected BEGIN_OBJECT but was BEGIN_ARRARY at line 1 column 2 path$
- 1
发现自己解析的时候,使用的是对象,而非数组。但是以上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;
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
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<List<ChannelBean>> getChannel(@Query("client_id") String client_id);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
Observable<List<ChannelBean>>
这里必须使用对象容器来保存json数组。
转自XKCK的博客:http://blog.csdn.net/WiseClown/article/details/52024541