错误:E/AndroidRuntime(2711): java.lang.IllegalStateException: 应为名称,但为 STRING
评估下的文件(测试)的内容:
[
{
"title": "baidu",
"url": "http://www.baidu.com"
}
]
解析代码:
new Thread(){
@Override
public void run()
{
try
{
InputStream is = MainActivity.this.getResources()
.getAssets().open("test");
InputStreamReader in = new InputStreamReader(is);
JsonReader reader = new JsonReader(in);
reader.beginArray();
while(reader.hasNext())
{
reader.beginObject();
while(reader.hasNext())
{
System.out.println(reader.nextName());
}
reader.endObject();
}
reader.endArray();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}.start();