0
我得到它可能是兩GSON解析陣列
"data": [
{
"uuid": ".......",
"error": true,
"code": 142,
"text": "Invalid uuid"
}
]
或
"data": {
"download_url": "http://....."
}
以分析它在我的應用程序一個I與改型得到它作爲一個對象的響應
public class downloadFileResponse extends generalStatusResponse {
Object data;
public Object getData() {
return data;
}
}
,並嘗試分析它像這樣
if (response.getStatus().getCode().equals("136")) {
String res = new Gson().toJson(response.getData());
try {
JSONObject t = new JSONObject(res);
Log.v("this", "r- " + t.getString("download_url"));
} catch (Exception e) {
}
} else {
try {
List<downloadFileDataErrorFields> error = new Gson().fromJson(response.getData().toString(), new TypeToken<List<downloadFileDataErrorFields>>() { }.getType());
} catch (Exception e) {
e.printStackTrace();
}
}
和我downloadFileDataErrorFields對象是這個
public class downloadFileDataErrorFields {
String uuid;
String error;
String code;
String text;
public downloadFileDataErrorFields() {
}
public String getUuid() {
return uuid;
}
public String getError() {
return error;
}
public String getCode() {
return code;
}
public String getText() {
return text;
}
}
只用它工作正常的DOWNLOAD_URL第二反應,但是當我嘗試分析第一個與錯誤,我得到這個
Caused by: com.google.gson.stream.MalformedJsonException: Unterminated object at line 1 column 87 path $[0].text
在此列中,「Invalid uuid」字符串中有一個空格。
任何人都知道如何解決這個問題?或者正確解析不同類型的響應?
謝謝
第一個JSON是無效的。 –