Android : Best way to store static nested data(array) in Android?

on Friday, August 22, 2014


So I have data, for example:



1 topic will be conducted in 2 class room with different subtopic each hour from 9am-12pm.



It will look like below if in JSON format:



{
"Mathematic": [
{
"time": [
{
"startTime": "09.00",
"endTime": "10.00",
"class": [
{
"subtopic": "What is Calculus?",
"roomName": "Class A"
},
{
"subtopic": "Basic of Calculus",
"roomName": "Class B"
}
]
}
]
}
]
}


If I put the json file in res folder, I believe the JSON parser will take some time to parse it.


I also think about to put it in arrays.xml:



<array name="testArray">
<item>first</item>
<item>second</item>
<item>
<array name="testArrayNested">
<item>
first nested
</item>
<item>
second nested
</item>
</array>
</item>
<item>fourth</item>
<item>fifth</item>
</array>


I am not sure how to get the nested array, here is my code:



String [] test = getResources().getStringArray(R.array.testArray);
for(int i = 0; i < test.length; i++)
System.out.println("test: " + test[i]);


Output:



test: first
test: second
test: first nested second nested
test: fourth
test: fifth


What is the best way to store the static data?


0 comments:

Post a Comment