android – Save information to SQLite and then upload to JSON with webserve

Question:

I read several tutorials on how to get a JSON and pass the information to a SQlite, but as I do the reverse, I get the application data already saved in SQLite and then transfer it to a webservice with JSON… thanks in advance

Answer:

Add google's Gson dependency to your gradle, you have it in the m2Repository, you will do your search in the normal database, transform it into a normal java object and then just call gson like this

new Gson().toJson(object).build();

I don't remember exactly if it's like that, if that's what you really want, I recommend taking a look at the Gson documentation, it's a great class, I always use it, it's so simple I don't even remember how I do it…

In the documentation there are annotations that you can make in your classes to be able to customize the json, take or not a field and change the name that it comes in the json…

https://github.com/google/gson/blob/master/UserGuide.md#TOC-Goals-for-Gson

I believe this link will answer your questions…

Scroll to Top