Gson .JsonSyntaxException - java.lang.NumberFormatException:无效的double:“”

时间:2014-08-05 13:34:36

标签: android json gson

我运行此代码并崩溃。你能帮帮我吗?

public class RepairCostsData {

@Expose
private int month;
@Expose
private int month_id;
@Expose
private int year;
@Expose
private double summa;
@Expose
private double detail_price;
@Expose
private double job_price;

...

为此课程调用Gson()。fromJson()

RepairCostsData[] repairCostsData = new Gson().fromJson(jsonObject.getJSONArray(DATA).toString(),
                                                                RepairCostsData[].class);

**来自服务器**的JSON

[{ “月”: “”, “month_id”: “3”, “年”: “2014”, “detail_price”:0 “job_price”:0, “总结”:0},{“月“:” “ ”month_id“: ”4“, ”年“: ”2014“, ”detail_price“:0, ”job_price“:0, ”大全“:0},{ ”月“: ”“,” month_id “:” 5" , “年”: “2014”, “detail_price”:0, “job_price”:0, “大全”:0},{ “月”: “”, “month_id”: “6”,”一年 “:” 2014" , “detail_price”:0, “job_price”:0, “大全”:0},{ “月”: “Июль”, “month_id”: “7”, “年”: “2014” “detail_price”: “250.00”, “job_price”:0, “大全”:250},{ “月”: “”, “month_id”: “8”, “年”: “2014”, “detail_price”: 0 “job_price”:0, “总结”:0}]

记录

 com.google.gson.JsonSyntaxException: java.lang.NumberFormatException:
   Invalid double: ""
               at com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:232)
               at com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:222)
               at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93)
               at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172)
               at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
               at com.google.gson.internal.bind.ArrayTypeAdapter.read(ArrayTypeAdapter.java:72)
               at com.google.gson.Gson.fromJson(Gson.java:791)
               at com.google.gson.Gson.fromJson(Gson.java:757)
               at com.google.gson.Gson.fromJson(Gson.java:706)
               at com.google.gson.Gson.fromJson(Gson.java:678)
               at com.DriverNotes.AndroidMobileClientTest.model.server.statistics.RepairCosts.<init>(RepairCosts.java:29)
               at com.DriverNotes.AndroidMobileClientTest.model.server.statistics.RepairCostsStatistics.<init>(RepairCostsStatistics.java:20)
               at com.DriverNotes.AndroidMobileClientTest.network.VolleyServerConnector$48$1.run(VolleyServerConnector.java:780)
               at java.lang.Thread.run(Thread.java:856)

此行崩溃:

RepairCostsData[] repairCostsData = new Gson().fromJson(jsonObject.getJSONArray(DATA).toString(),
                                                                RepairCostsData[].class);

2 个答案:

答案 0 :(得分:4)

&#34; job_price&#34;:&#34; 0.00&#34;不是双重而是字符串,

更改为

"job_price": 0.00

答案 1 :(得分:2)

private int month;

"month":"Июль"

也不匹配