gson

How to deserialise .NET JsonResult DateTime format with Gson in Android?

ε祈祈猫儿з 提交于 2020-01-07 00:06:19
问题 I have a JSON returned from server in this format: { "StartDate": "/Date(1451593800000)/", "EndDate": "/Date(1483216200000)/" } And in my POJO: public class Data { java.util.Date startDate; java.util.Date endDate; } And my Gson object: private final Gson gson = new GsonBuilder() .serializeNulls() .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE) .create(); When I wanted to parse this JSON I get this error: Unparseable date: "/Date(1483216200000)/" (at offset 0) What is the right way

How to filter JSON String array based on attributes?

只谈情不闲聊 提交于 2020-01-06 23:51:04
问题 I have a JSON-String array, where its entry has the following properties, firstName , lastName , loginName , Country , phoneNumber , and status . Here's an example [ { "firstName": "Patrick", "lastName": "Smith", "loginName":"test0003@test.com", "Country":"US", "phoneNumber": "287 125-1434", "status": "340" }, { "firstName": "Bob", "lastName": "Williams", "loginName":"test0002@test.com", "Country":"US", "phoneNumber": "213 111-9943", "status": "215" }, { "firstName": "John", "lastName":

Android: Gson deserializes Integer as Double

喜欢而已 提交于 2020-01-06 19:57:40
问题 I am trying websockets on android using this library WebSocketRails-Android but I want to replace Jackson with Google's Gson but I am having a problem on deserialization. So on receiving a JSON string like this [["websocket_rails.subscribe",{"id":1676395261,"channel":null,"user_id":null,"data":{"message":"Connected successfully to 82c6"},"success":true,"result":null,"token":null,"server_token":null}]] Gson deserializes it and gives me the id = 1.676395261E9 I am deserializing like this

Gson serialized name: “Implicit super constructor Object() is undefined for default constructor. Must define an explicit constructor”

大憨熊 提交于 2020-01-06 18:07:42
问题 I'm new to Android, and I'm trying to learn how to use Gson to parse an API call. I've read around a little bit, and I'm trying to follow this example: http://www.javacodegeeks.com/2011/01/android-json-parsing-gson-tutorial.html It's going relatively well, but when I imported the project into Eclipse to get a better look at the code, I encountered the error above regarding constructors (as well as a few other confusing errors). I read some related questions here on StackOverflow, but they all

What should be my class structure to parse JSON in GSON

梦想的初衷 提交于 2020-01-06 16:11:30
问题 I have the following JSON data: { "response": {}, "errorMessage": { "error": [ { "errorId": 260003, "domain": "ads", "subdomain": "asd", "severity": "asd", "category": "asd", "message": "asdsa asd ad", "errorName": "UnAuthorized" } ] } } Currently I have the following class structure: public class JSONCollection private Response response; private ErrorMessage error; public class Response private String collectionId; private String url; public class ErrorMessage private List<ErrorValues> error

Unable to parse different json format string via GSON

痴心易碎 提交于 2020-01-06 15:46:48
问题 This is not a duplicate question Please dont mark it as duplicate. Can this Json be parsed with GSON library? {"keyobject": {"keyarray": ["key1", "key2", "key3"]}, "valueobject": [{"valuearray": ["arr1_val1", "arr1_val2","arr1_val3"]}, {"valuearray": ["arr2_val1", "arr2_val2","arr2_val3"]}]} 回答1: How about this? class Outer { KeyObject keyobject; List<ValueObject> valueobject; } class KeyObject { List<String> keyarray; } class ValueObject { List<String> valuearray; } Outer outer = gson

parse JSON with GSON returns null

送分小仙女□ 提交于 2020-01-06 13:38:27
问题 Here is my Json : [ { "canaldsc":"PHARMA", "cadenadsc":null, "formatodsc":"DEL AHORRO", "estadodsc":null, "ciudaddsc":"VALLE DE MEXICO", "regiondsc":"CENTRO SUR", "proyectotiendaid":null, "proyectoid":"79", "planid":"54", "proyectodsc":"Concurso", "vigencia":"0000-00-00", "activo":"1", "usuarioproyectotiendaid":"65280", "proyecto":null, "fechainicio":"2014-03-24", "lunes":"7", "martes":"7", "miercoles":"7", "jueves":"7", "viernes":"7", "sabado":"7", "domingo":"7" }, { "canaldsc":"PHARMA",

Making GsonRequest to accept empty list or null array

谁说我不能喝 提交于 2020-01-06 13:12:48
问题 I have a Json data to be pulled from a server. This data contains several objects and arrays. The first model is as follows: { "results": [ { "id": "17", "name": "Accessories", "child": [ { "id": "371", "name": "Belt" }, { "id": "55", "name": "Derp" }, ... ] } ] } However, some of the results array doesn't have child array. Instead, it have a String with an empty value. { "results": [ { "id": "19", "name": "Stuff", "child": "" } ] } When the code is executed, it returns this line: com.google

Phrasing Json Array using Gson for google search api

萝らか妹 提交于 2020-01-06 13:11:14
问题 First of all Sorry for the really long post, now And this is my class structure, no idea if it's right or wrong public class GoogleResponse { public ResponseDate responseData; public String responseDetails; public String responseStatus; } public class ResponseData { public List<Result> results; //public Cursor cursor; } public class Result { public String titleNoFormatting; public String unescapedUrl; } And this is the code for deserialization Gson gson = new Gson(); GoogleResponse data[] =

gson --> “No-args constructor for class xyz” with arrays

北城余情 提交于 2020-01-06 08:41:48
问题 i try to deserialize a json string with the help of gson. While gson.fromJson I get the following error: No-args constructor for class xyz; does not exist. Register an InstanceCreator with Gson for this type to fix this problem I tried to work with an InstanceCreate but I didn't get this running. I hope you can help me. JSON String [ { "prog": "Name1", "name": "Name2", "computername": "Name3", "date": "2010-11-20 19:39:55" }, { "prog": "Name1", "name": "Name2", "computername": "Name3", "date"