I am currently developing application that store some trip's data on array. As we know in android development we can use hash-map for storing data into fire-store but that not fit what i need , it store the data without array index. is there any idea to structure the data as it shows on the attached screenshot. Thanks in advance
To store an indexed array of items in the field of a document, use an ArrayList.
For an application which will allow members of my organisation to see data on their mobile device i need to store pre-formatted data on the device so they can see it offline as well. How they get the data is trough a JSON request-response.
The response is formatted as follows (anonymised ofc):
[{
"firstname":"John",
"lastname":"Smith",
"group":"1",
"age":11,
"installed":"Ja",
"medical":"Is aan zijn linker zijde verlamd geweest.",
"notes":"Heimee. \r\nBeschermend opgevoed. \r\nTerug getrokken persoonlijkheid.",
"Insignes":["test", "Test2"],
"Parents":[]
},
{
"firstname":"Emely",
"lastname":"Watson",
"group":"33",
"age":14,
"installed":"Ja",
"medical":"",
"notes":"Test",
"Insignes":["Veilig & Gezond I","CWO II","CWO III","Kampeertechnieken & Pionieren"],
"Parents":[
{
"name":"ouder ouder",
"address":"op | 0000AA Amsterdam",
"phone1":"",
"phone2":"0612345678",
"mail":"example#google.com"
}]
}]
I have read a couple of discussion on how to best store this:
Is it ok to save a JSON array in SharedPreferences?
How to save JSON Array in SharedPreferences?
Android: what is the best way to store JSON data offline for the app in android?
Android - how to add JSON object to sharedPreferences?
What is the advantage of Using SQLite rather than File?
From reading these I have gathered that SharedPreference files are "faster" than sqlite but are prone to corruption. SQLite is a database and since the data comes from one I am inclined to use that at the cost of processing speed.
Now I only need to store and then read the data, it wont be mutated unless there is an update on the "main server" in which case I will probably wipe the local data and repopulate it. In these threads i have read that storing JSON in sharedpreference is easy but difficult to read.
But after reading these (and more) discussions I am no closer to knowing/deciding what the best way to store my json is.
Any advice is greatly appreciated!
You can try the ORMs like Realm or sugarORM and store the json has object in the database. They also provide the Cipher options by which you can encrypt the data too, Which would be more flexible.
http://www.androidauthority.com/use-android-keystore-store-passwords-sensitive-information-623779/
http://www.androidhive.info/2016/05/android-working-with-realm-database-replacing-sqlite-core-data/
If you don't need to use any ORM by third parties then you can directly encrypt the JSON string with the android keystore keys and then can store the encrypted string in the normal sqlite.
This is opinion based answer. Android no I wouldn't store JSON in a DB or preferences. Store the json in a file. A file can be accessed as stream the same way you stream access json. Virtually no upper limit on size in a file. I might store a link to the json file in a DB or preferences. Depending on application I might just extract json into abstract elements and store in DB for ordering selection.
The data you have provided depending on sensitivity I would extract and insert into the contacts database for the device.
The best option is to go with a database approach, for one it sounds your dataset might be large are rather expected to be large. Database persist large sets of information, however I do not recommend using SQLITE , for it is sql based, no ORM and the operations can get tedious and time consuming and mainly it is slow(debatable). Rather use the hottest and latest no-sql database for android and ios, which Realm, realm is super fast, it is based on java annotations and ORM(like hibernate). To work with json in android I recommend familiarizing yourself with GSON, A Java serialization/deserialization library that can convert Java Objects into JSON and back.
Shared Preferenences are really convenient to store small key value pairs, If you have a relatively small collection of key-values that you'd like to save, you should use the SharedPreferences APIs. A SharedPreferences object points to a file containing key-value pairs and provides simple methods to read and write them. You would of to still work with gson here, I never heard of a shared preference getting corrupted, what I do know is that they are fragile,and live with the existence of your app installation.
Conclusion: If your dataset is large use a database approach to persist large dataset, maintenance and modifications are more fluent here, however if you know that whatever you are storing is relatively small, use a shared pref, and to manipulate json constructs in android to and fro use the google gson library.
SharedPreferences :
If you have small amount of data in Json then you have to store it in SharedPreferences.
You can easily store Json to SharedPreferences using Gson. Just using this :
Convert Json to String :
Gson gson = new Gson();
String jsonString = gson.toJson(jsonData);
Convert String to Json :
gson.fromJson(jsonString, TypeToConvert);
Sqlite Database :
If you have large amount of data in Json then just go with Sqlite.
I have an sqlite database. The column where I want to save my JsonString in, has the data type TEXT. Everytime I want to insert a dataset I get no error until I try to read it out again, then I get an error that my curser may be at the wrong place. But when instead of a json give a usual string everything works fine. Since I don't really now what symbols might be in my json, is there at all a way to put a json into an sqlite database? (It is a large json so I can't really insert every value of it seperatly).
How can I save a JsonString else so that I can get I even if my application is closed?
I know I could put it in al file but since a database has a better structure and basiccly is a file too I would prefer to find a way working with the database.
Save as a string:
json.toString();
Although I would parse it, it is faster this way.
Can we convert json format data coming from server into mysql database or means can we store
the data coming through json into mysql database.
Thanks .
Although not a 'yes' in the sense that you can just shove a JSON string at MySQL and have it insert the data itself, yes, you can programmatically take a JSON string, parse it, and insert that data into a MySQL database. You may want to look at something like JSON-to-MySQL, which is a set of PHP scripts that can take arbitrary JSON data and convert it to SQL data.
The most common way is parser you Json data to Object and store it in database.
I recommend you use Jackson, see here and here a simple example.
Hope its help
So I have an SQLite table that is internally stored with an id, latitude, longitude, and time. I would like to send that table to my external SQL Server through a webservice. Populating a JSON Array with my SQLite data and passing that array to a webservice which then does some processing and stores it in the SQL Server seems like the best way to achieve this. I am confused as to the best way of populating the JSON array from my SQLite table. Could anyone provide some example code or maybe link to a tutorial?
to check you json "query"
tutorial, oficial web page