我想用GSON來解析一些非常簡單的JSON。這裏是我的代碼:GSON:期望一個字符串,但是BEGIN_OBJECT?
Gson gson = new Gson();
InputStreamReader reader = new InputStreamReader(getJsonData(url));
String key = gson.fromJson(reader, String.class);
這裏的JSON從URL返回:
{
"access_token": "abcdefgh"
}
我得到這個異常:
E/AndroidRuntime(19447): com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 2
任何想法?我是GSON的新手。
尼斯答案布魯斯! – 2012-07-20 12:43:59
我可以打一箇舊的線程,新的Json,你可以簡要解釋一下你的第一個答案,我很困惑把Map放入類型token ..關於** fromJson()的第二個參數**()**方法 – SSH 2015-07-28 11:01:40