skip to Main Content

i have a form to get user name , phonenumber, street , province and i want to save this in local with Shared Preferences like this to read i have card for each adress inside tha card it will show the details of the card so how can i do that?

{
"address1": {
    "name": "afthal",
    "phonenumber": "123456",
    "street": "197/F",
    "province": "Puttalam"
},
"address2": {
    "name": "afthal",
    "phonenumber": "123456",
    "street": "617/E Mannar",
    "province": "Colombo"
},
"address3": {
    "name": "afthal",
    "phonenumber": "123456",
    "street": "45 UC Road",
    "province": "Jaffna"
}

}

2

Answers


  1. hope you are fine,

    The best solution is to use a local database, but if you insist to use shared preferences, you can do this approach:

    1. Encode the JSON and convert it to String.
    2. Save the string in the SharedPref.
    3. When you want to retrieve it -> get the String from SharedPref -> use json decode to decode it -> you will get. the Map (JSON) -> convert it to a list of addresses.
    Login or Signup to reply.
  2. Simple Solution:

    Instead of storing each address card in the local database, try to convert your Address Card List to String and store this String in Shared Preferences which contains all addresses.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search