1

I'm working on a little Android project in java, I'm using the webapi of spotify to get me so data to play around with.

First thing I notice when visiting: https://developer.spotify.com/technologies/web-api/ is that a developer can choose to use xml or json.

What i would like to do is 'cache' my data so i can do the following:

  • read one value from the file, or construct an object based on different values
  • add the object created above to the lisviewadapter
  • update the listview with the updated adapter
  • iterate over previous steps until parsing of file is complete

I want to be as quick as possible for my users so that the ui gets updated while parsing and loading the data. For this I sketched 2 use-cases.

  • add items to the listview until done
  • show a X amount of items and show a load more button

What file type is more ideal to use for my problem? xml parsing or json parsing?

How can i do this parsing? which tools meet my requirements?

Which use-case seems better to use?

any tips if you have done something like this in the past?

any guidance is appreciated

Tobrun
  • 17,781
  • 10
  • 62
  • 78

2 Answers2

2

I don't make any distinction between XML or JSON. To cache data you have two options. Either write the data to a file (will require reparsing of the file to extract the data (unless you create a new file of, for example, CSV data)) or write the required data to a database after parsing. As for updating ListView, that would be up to you based on the number of entries you have.

Android has both XML and JSON parsers built-in. You don't need GSON.

techiServices
  • 8,293
  • 4
  • 35
  • 41
  • First of all, thank you for your response. I`m thinking about using sql lite to persist the data as you mentioned. But what would be the advantage of the build in parsers over the GSON? Would you rather use for example a SAX parser? and why? is GSON slow? – Tobrun May 15 '12 at 08:29
  • 1
    I haven't used GSON but it appears to be more like `DocumentBuilder` which creates XML as well as parsing it. If you don't need to create XML/JSON then just use a pure parser to extract the data. `DocumentBuilder` is much slower and weightier than `XMLReader`. – techiServices May 15 '12 at 08:36
1

I'd recommend JSON because JSON uses less bandwitch for transfering and google has made an awesome json parser library called GSON.

Warpzit
  • 27,293
  • 18
  • 98
  • 146
  • Thank you for replying, i will look at the implementation of GSON. What it`s your oppinion about caching this json data, would it be easy to use GSON in combination with for example SQL-lite to persist the data? – Tobrun May 15 '12 at 08:19
  • 1
    Well GSON makes it easier to create objects from JSON and create JSON from objects. It doesn't manage sql-lite for you. So in that aspects JSON doesn't have advantage over XML. But the ease of access to the data of JSON kinda makes it easier to get the data to and from sql :) – Warpzit May 15 '12 at 08:22