Dan
Dan

Reputation: 17

Android - How do you save a .JSON to a device?

I have created an application. Which gets a .JSON file from a server and reads it.

What I would like to do is to save it onto the device as a .JSON file before it actually does any reading. The reason why I would like to do this, is so you dont need to have an internet connection every time a client uses my application.

Here is an example of the JSON

{
"CARS LIST":
    {
    "Car":
        {
        "Make":"BMW",
        "Model":"M3",
        "Engine":"4.0",
        "Desc":"M Power!",
        },

    "Car":
        {
        "Make":"Mercedes",
        "Model":"SLS",
        "Engine":"6.2",
        "Desc":"AMG!",
        }
    }
}

Upvotes: 0

Views: 230

Answers (2)

Dan
Dan

Reputation: 17

This is how I done it.

  1. Get the inputstream
  2. Using inputstream.read(byte[] buffer, int offset, int length) store the data as a byte[].
  3. Put the byte[] into a char[].
  4. Save onto device

Upvotes: 0

Amrut
Amrut

Reputation: 543

You can save this response as a text file with timestamp in filename. This will tell you upfront when was data updated last time.

Upvotes: 1

Related Questions