【发布时间】:2015-11-10 13:30:17
【问题描述】:
在线上
reader.beginArray();
我得到错误:
expected beginarray but was beginobject.
我尝试将.beginArray() 更改为.beginObject(),但它不起作用。
此代码是JsonParser 的一部分
public List<Noticias> leerArrayNoticias(JsonReader reader) throws IOException {
ArrayList<Noticias> noticias = new ArrayList<>();
try {
reader.beginArray();
while (reader.hasNext()) {
noticias.add(leerNoticia(reader));
}
reader.endArray();
}catch(IOException e){
e.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
return noticias;
}
这是我试图解析的 Json
{"noticias":
[
{"idnoticias":"109","titulo":"nueva1","descripcion":"nuevo1"},
{"idnoticias":"110","titulo":"nueva2","descripcion":"nuevo2"}
]
}
【问题讨论】:
-
JSON 长什么样?问题可能是异常所说的,json 以对象而不是数组开头。你说过你试过了,但你能给我们那个错误的堆栈跟踪吗?
-
尝试使用一个对象 sais "java.lang.IllegalStateException: Expected BEGIN_OBJECT but was NAME"
-
JSON 无效,贴出来让我改正
-
格式,简化标题
标签: java android arrays reader