2012-08-22 59 views
0

我用下面的代碼到我的JSON字符串轉換爲對象:GSON錯誤

Gson gson = new Gson();    
EntPocketPCDataCollection entPocketPCDataCollection = gson 
      .fromJson(strJson, 
      EntPocketPCDataCollection.class); 

我有這些類:

public class EntPocketPCDataCollection extends ArrayList<EntPocketPCData> { 

    private static final long serialVersionUID = 1L; 

} 

public class EntPocketPCData { 

    private String strFormat = "Can not convert %s to %s value for column %s"; 

    public String Command; 
    public EntColumn[] Columns; 
    public List<List<String>> RowsList; 
    public String TypeName; 
} 

這些代碼行可以在Emulator,Asus tablet,galaxy note,galaxy s和HTC Sensation上正常工作。但是,僅在具有Android 2.2的HTC Desire HD A9191設備上出現以下錯誤。

爲什麼?

com.google.gson.JsonParseException: The JsonDeserializer [email protected]08 
failed to deserialized json object [{"Command":"Insert","Columns":[{"Name":"Id","Type":"System.Int32"}, 
{"Name":"Caption","Type":"System.String"},{"Name":"Category","Type":"System.String"}, 
{"Name":"DefaultValue","Type":"System.String"},{"Name":"Description","Type":"System.String"}, 
{"Name":"Name","Type":"System.String"},{"Name":"Val1","Type":"System.String"},{"Name":"Val2","Type":"System.String"}, 
{"Name":"Val3","Type":"System.String"},{"Name":"Val4","Type":"System.String"},{"Name":"ValDesc1","Type":"System.String"}, 
{"Name":"ValDesc2","Type":"System.String"},{"Name":"ValDesc3","Type":"System.String"}, 
{"Name":"ValDesc4","Type":"System.String"},{"Name":"Visible","Type":"System.String"}, 
{"Name":"order","Type":"System.Int32"}],"RowsList":[[7,"تعداد رقم اعشار","Common","0","تعداد رقم 
اعشار","Common_DecimalDigits","","","","","","","","","false",1],[8,"فلدر مستندات برنامه","Common","","مستندات و عکس هاي 
دريافتي از وب سرويس در اين فلدر ذخيره مي شود","Common_DocumentsFolder","","","","","","","","","false",1],[9,"بازه زماني همسان سازي 
سريع","DataExchange","-1","بازه زماني همسان سازي سريع","DataExchange_SyncPartial_Interval","","","","","","","","","false",1], 
[10,"بازه زماني همسان سازي کامل","DataExchange","-1","بازه زماني همسان سازي 
کامل","DataExchange_SyncFull_Interval","","","","","","","","","false",1],[11,"بازه زماني ارسال سفارشات","DataExchange","2","بازه 
زماني ارسال سفارشات","DataExchange_Send_Interval","","","","","","","","","false",1],[12,"آدرس وب سرويس 
شرکت","WebService","http://test/MobileService/Service.asmx","آدرس وب سرويس داخلي شرکت جهت تبادل اطلاعات با 
سرور","WebService_URL","","","","","","","","","false",1],[13,"آدرس وب سرويس 
","WebService","http://test/Service.asmx","آدرس وب سرويس جهت دريافت 
قفل","WebService_URL","","","","","","","","","false",1],[15,"شماره سرور","SMS","","شماره 
سرور","SMS_Server_NO","","","","","","","","","false",1],[17,"ارسال پيامک","SMS","0","نحوه ارسال 
پيامک","SMS_SendingOption","0","1","2","","عدم ارسال پيامک","ارسال پيامک با سوال از کاربر","ارسال پيامک بدون سوال از کاربر","","false",1], 
[18,"بازه زماني دريافت مکان جاري کاربر","GPS","2","بازه زماني دريافت مکان جاري کاربر","GPS_Interval","","","","","","","","","false",1], 
[19,"وضعيت مکان يابي","GPS","1","وضعيت مکان يابي","GPS_StartOption","0","1","2","","خاموش","روشن","روشن در غير اينصورت خروج از 
برنامه","","false",1],[20,"نحوه ارسال پيامک جي پي اس","GPS","false","هنگام ارسال پيامک درخواست اگر اين مقدار فعال باشد، چهار نقطه آخر دريافتي نيز با 
پيامک ارسال مي شود","GPS_SendSms","","","","","","","","","false",1],[21,"بازه ارسال پيامک جي پي اس","GPS","-1","اگر تنظيمات ارسال پيامک 
جي پي اس فعال باشد بازه زماني ارسال پيامک بر حسب دقيقه را مشخص مي کند","GPS_SmsInterval","","","","","","","","","false",1],[24,"نام کاربري 
فعالسازي ","Security","1","نام کاربري فعالسازي ","Security_UserName","","","","","","","","","false",1],[25,"کلمه عبور 
فعالسازي ","Security","","کلمه عبور فعالسازي ","Security_Password","","","","","","","","","false",1],[26,"مشخصه شرکت دوره 
مالي","Common","2012","مشخصه شرکت دوره مالي","Common_ScuCmpyDurID","","","","","","","","","false",1],[27,"مشخصه عمليات ثبت 
سفارش","Common","3","مشخصه عمليات ثبت سفارش","Common_InvOperationIDOrder","","","","","","","","","false",1],[28,"مشخصه 
عمليات اعلام برگشتي","Common","53","مشخصه عمليات اعلام برگشتي","Common_InvOperationIDBack","","","","","","","","","false",1], 
[29,"مشخصه مرکز هزينه","Common","10","مشخصه مرکز هزينه","Common_TotCostCenterID","","","","","","","","","false",1],[30," 
مشخصه ويزيتور","Common","8","مشخصه ويزيتور","Common_HrsEmployeeID","","","","","","","","","false",1],[32,"مقدار تعيين کننده فعال 
بودن برنامه توسط شرکت محلي","Security","true","مقدار تعيين کننده فعال بودن برنامه توسط شرکت 
محلي","Security_ActivationCompany","","","","","","","","","false",1],[33,"فعال بودن پروتکل پرينتر","Printer","false","فعال بودن پروتکل 
پرينتر","Printer_Protocol","","","","","","","","","true",1],[34,"نام پرينتر","Printer","","نام 
پرينتر","Printer_Name","","","","","","","","","true",1],[36,"آخرين شماره سريال ثبت شده سندها","Common","5","آخرين شماره سريال ثبت شده 
سندها","Common_Serial","","","","","","","","","false",1],[37,"آدرس سرور اف تي پي جهت دريافت فايلها","Ftp","ftp://1.2.3.4","آدرس سرور 
اف تي پي جهت دريافت فايلها","Ftp_URL","","","","","","","","","false",1],[38,"نام کاربر سرور اف تي پي","Security","ftpuser","نام کاربر 
سرور اف تي پي","Security_FtpUserName","","","","","","","","","false",1],[39,"رمز عبور سرور اف تي پي","Security","Symbian1","رمز 
عبور سرور اف تي پي","Security_FtpPassword","","","","","","","","","false",1],[40,"آدرس وب سرويس دريافت 
نقاط","WebService","http://test/MobileService/Service.asmx","آدرس وب سرويس دريافت موقعيت 
ويزيتور","WebService_GpsPointsURL","","","","","","","","","false",1],[41,"آدرس داخلي وب 
سرويس","WebService","http://test/MobileService/Service.asmx","آدرس داخلي وب 
سرويس","WebService_LanURL","","","","","","","","","false",1],[42,"کنترل نمايش موجودي","Common","true","کنترل نمايش 
موجودي","Common_ShowStockQty","","","","","","","","","false",1],[43,"فيلتر کردن مشتري ها بر اساس فاصله","Common","false","مشترياني 
که در فاصله مشخصي از ويزيتور هستند نشان داده مي شوند","Common_FilterNearCustomers","","","","","","","","","false",1],[44,"نمايش مشتريان 
اطراف در اين فاصله به متر","Common","50","فقط مشترياني که در اين فاصله از ويزيتور هستند نمايش داده مي 
شوند","Common_NearCustomersDistance","","","","","","","","","false",1],[45,"نمايش اعتبارسنجي مشتري","Common","true","اطلاعات 
اعتبارسنجي و صورت وضعيت مشتري نمايش داده مي 
شود","Common_ShowCustomerCredit","","","","","","","","","false",1]],"TypeName":"EntPreferences"}] given the type class 
org.order.dataModel.transferTools.EntPocketPCDataCollection 

回答

1

我們曾經嵌在我們的應用程序上的Desire HD與GSON一個問題,因爲不是我們gson.jar文件在運行時使用,但一個過時的版本,HTC發佈了它的ROM。我想你也有類似的問題。一種可能的解決方法是使用jarjar(http://code.google.com/p/jarjar/)以確保您的應用程序使用您的gson jar。

編輯 最可能的是同一個問題在這裏:GSON + HTC Desire: Conflict. Possible solution jarjar.jar causes error

+0

感謝。它解決了我的問題! – breceivemail

+0

完整地描述了[here](http://mukeshyadav4u.blogspot.ch/2012/05/java-gsonjson-deserialization-error.html)。 – breceivemail