2012-04-02 141 views

回答

0

根據你正在尋找的領域,你可能只是不序列化該對象。例如:

public class test{ 

    String somString; 
    Map<String,String> thisValueThrowsTheError; 
    Int somInt; 
} 

如果你想忽略這個Map對象,你能做到這一點是這樣的:

public class test{ 

    String somString; 

    @SerializeName("NOTAVALIDJSONOBJECTNAME") 
    Map<String,String> thisValueThrowsTheError; 
    Int somInt; 
} 

GSON不會看到一個名字爲地圖,它會跳過該對象。

或者(最終更好的解決方案)就是使用Deserializer來解決您正確的問題。看到這個帖子的解串器的例子:

Gson deserialization - Trying to parse a JSON to an Object