0

Possible Duplicate:
Save data from Json object to Database (SQLite)

I am making an android app that gets data from server, save it and use those data later when there is no connectivity. How to save JSON object in SQLite database, I have no clue. Please give me some example to understand it better. I really appreciate your help. Thanks.

Community
  • 1
  • 1
  • why you saving into sqlite instead of mysql because JSON, PHP and ANDROID works perfect together. – Zamani Jul 09 '12 at 11:25

4 Answers4

1

Transform the json to string and just insert it to the database. When you need it , retrieve it from database and use :

data = new JSONObject(str).getJSONObject("data");

str = json string retrieved from database

Razvan
  • 710
  • 3
  • 9
  • 25
0

Try this...

I am assuming that now you are getting the data from JSON object, and the issue is saving it.

  1. See the type of the fields and the numbers of fields that you want to store in SQLITE DB.

  2. Store the values in JSON objects in their corresponding data types.

  3. Suppose JSON object User has 4 fields

    Name - String Password - String or char[] Age - int City - String

  4. Retrive the values as below.

    jsonObject.getString("name");

    jsonObject.getString("password");

    jsonObject.getInt("age");

    jsonObject.getString("city");

Kumar Vivek Mitra
  • 33,294
  • 6
  • 48
  • 75
0

is perfect to save in mysql using JSON, PHP and ANDROID because they work perfect together rather than trying in sqlite

Mr Mashabela
  • 112
  • 2
  • 10