mt0s
mt0s

Reputation: 5821

What format should i use to save JSON data in android

In what format should i save the JSON data i get from a server in order to populate them later in a ListView ?

Is a 2 dimensional array enough or is there a better solution?

Every JSON Object is like :

       {"id":"1","title":"London"}

Upvotes: 1

Views: 155

Answers (2)

Teraiya Mayur
Teraiya Mayur

Reputation: 1154

You can use:

Arraylist<ClassName> jsondata=new ArrayList<ClassName>

Here's an example:

public Class ClassName 
{

  string fname;
  string lname;

public void setfname(String fname)
{
  this.fname=fname;
}

public void setlname(String lname)
{
  this.lname=lname;
}

public String getlname(String lname)
{
  return lname;
}
public String getfname(String fname)
{
  return fname;
}

You can store it like this..

Upvotes: 3

alexfernandez
alexfernandez

Reputation: 1978

Where do you want to save the data? If it's in a preferences object then the JSON itself is a good option. Otherwise a HashMap would be appropriate, and much better than the two-dimensional array: faster, more logical, better suited.

Upvotes: 1

Related Questions