can anyone help on this...
On Tue, May 13, 2014 at 8:45 PM, Abhilash Baddam < [email protected]> wrote: > Hi All, > > I am trying to parse a json response using gson library. The response > should contain always only one object(site) > I tried in so many ways but always getting the below exception. > But I am getting the below exception, > > com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: > Expected STRING but was BEGIN_OBJECT > at > com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:176) > > I have tried something like this, > > Gson gson = new > Gson(); > SiteDTO dto = new SiteDTO();//contains all setter and getter methods for > site object > // Type type = new > TypeToken<ArrayList<SiteDTO>>() { > // }.getType(); > //obj contains > JSONObject array = > obj.optJSONObject("site"); > > > dto=gson.fromJson(array.toString(), SiteDTO.class); //getting exception at > this statement > > /* JsonParser parser = new > JsonParser(); > JsonObject rootObejct = > parser.parse(obj.toString()).getAsJsonObject(); > JsonElement projectElement = > rootObejct.get("site"); > > dto = gson.fromJson(projectElement, > SiteDTO.class);*/ > > > Json String: > > { > "success": true, > "site": { > "id": 15251, > "site_name": "yuwa", > "technology": "GSM", > "market": "ARKANSAS", > "region": "Central", > "address": "HIGHLAND STREET", > "city": "GASSAWAY", > "state": "WV", > "zip": 26624, > "latitude": 38.6676, > "longitude": -80.7711, > "continuus_id": "2353001111", > "attachments": [ > { > "attachment_id": 3656, > "attachment_url": " > https://ldoapps.com/eams/web/uploads/sites/15251/4bd0c1fbcd29aa151db2850a52c81c8cbaabca2b/file_input.jpg > " > } > ], > "suppliers": [ > { > "company_id": 429 > } > ], > "aspsuppliers": [], > "is_archived": false, > "site_supplier_section": true, > "sp_activity_section": true, > "sp_activity_quote_section": false, > "sov_section": false, > "wa_section": false, > "bom_section": false, > "cop_section": true, > "site_attachment_section": true, > "punch_list_section": false, > "site_supplier_checklist_section": false, > "cop_acknowledgement": true, > "customer": {} > } > } > > Can anyone help me where I am doing mistake. > > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.

