I want to implement an app, that will show the route number, the rider has boarded in google map. So to find the route number I need some information about the routes, which are defined in the JSON file. The information in the JSON file will be proccessed and parsed offline from the app. It should be installed and uninstall with the app too. The JSON file contains more than 100 route_direction. It will looks something like the code below. In which folder can I store the JSON file in my Android project? And what is the best way to store data like this?
JSON file:
{"route_direction":[
{
1_ab:{
{
stopsName_arrivalTime:{"abc":{"mon-fri":[05:33,06:00,06:30,...],
"sat":[],
"son":[]
}
},
stops_loca:{lat:53.337994, long:10.600423} ,
},
{
stopsName_arrivalTime:{"def":{"mon-fri":[],
"sat":[],
"son":[]
}
},
stops_loca:{lat:53.740624, long:10.101322}
},
{
stopsName_arrivalTime:{"hgk":{"mon-fri":[],
"sat":[],
"son":[]
}
},
stops_loca:{lat:53.644834, long:10.203372}
}
}
},
{1_ba:{
{
stopsName_arrivalTime:{"hgk":{"mon-fri":[05:33,06:00,06:30],
"sat":[],
"son":[]
}
},
stops_loca:{lat:53.437994, long:10.400423} ,
},
{
stopsName_arrivalTime:{"def":{"mon-fri":[],
"sat":[],
"son":[]
}
},
stops_loca:{lat:53.540624, long:10.601322}
},
{
stopsName_arrivalTime:{"abc":{"mon-fri":[],
"sat":[],
"son":[]
}
},
stops_loca:{lat:53.244834, long:10.703372}
}
}
},........
]
}
json file is generally placed in the app/ directory (at the root of the Android Studio app module).
JSON is perfect for storing temporary data that's consumed by the entity that creates the data. A good example is user-generated data such as filling out a form or information exchange between an API and an app.
Android supports all the JSON classes such as JSONStringer, JSONObject, JSONArray, and all other forms to parse the JSON data and fetch the required information by the program. JSON's main advantage is that it is a language-independent, and the JSON object will contain data like a key/value pair.
JSON (Javascript Object Notation) is a programming language . It is minimal, textual, and a subset of JavaScript. It is an alternative to XML. Android provides support to parse the JSON object and array.
Maybe you can save them using SharedPreferences. You can store a json object/array by doing:
Saving json to SharedPreferences:
PreferenceManager.getDefaultSharedPreferences(context).edit()
.putString("theJson",jsonObject.toString()).apply();
Getting the stored json:
JsonObject jsonObject = PreferenceManager.
getDefaultSharedPreferences(this).getString("theJson","");
Basically, there are two places where raw stuff may be stored: assets/ and res/raw/ (raw resources). These have been discussed a lot, for example, see the links:
The reason for Assets and Raw Resources in Android
http://thedevelopersinfo.com/2009/11/27/using-files-as-raw-resources-in-android/
http://www.41post.com/3985/programming/android-loading-files-from-the-assets-and-raw-folders
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With