gson throws malformedJsonException
我正在使用gson将json字符串转换为Java对象。result2 的值与 result1 的值完全相同。(从调试器复制;已添加反斜杠)
转换 result1 时引发以下异常:com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Expected EOF 在第 1 行第 1 列 170
转换结果2工作正常。
json 字符串根据 jsonlint.com 有效。
public static Userinfo getUserinfo()
{
String result1 = http.POST("https://www.bitstamp.net/api/balance/",
postdata, true);
String result2 = "{\"btc_reserved\": \"0\", \"fee\": \"0.5000\", \"btc_available\": \"0.10000000\", \"usd_reserved\": \"0\", \"btc_balance\": \"0.10000000\", \"usd_balance\": \"30.00\", \"usd_available\": \"30.00\"}";
Gson gson = new Gson();
Userinfo userinfo1 = gson.fromJson(result1, Userinfo.class); //throws Exception
Userinfo userinfo2 = gson.fromJson(result2, Userinfo.class); //works fine
return userinfo1;
}
private class Userinfo {
public Userinfo(){
}
public float usd_balance;
public float btc_balance ;
public float usd_reserved;
public float btc_reserved;
public float usd_available;
public float btc_available;
public float fee;
public float last_update;
}