我正在使用gson将json字符串转换为Java对象。值RESULT2是完全一样的值RESULT1。(从调试器复制;添加了反斜杠)
转换result1时会引发以下异常: com.google.gson.JsonSyntaxException:com.google.gson.stream.MalformedJsonException:预期的EOF在第1行的第170列
转换result2效果很好。
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;
}