user2992724
user2992724

Reputation: 1

Android displayJSON data

I need to display some JSON data on an android app but I don't know how to do.

Example of JSON data

{
name: name,
surname: surname,
history: [{date: date, job: job}, {date: date, job: job}]
}

I want to show the list of job and date

String[] data = getResources().getStringArray(R.array.userData);

<TextView android:text="Date" />
<TextView android:text="@+id/job" />
<TextView android:text="Job" />
<TextView android:text="@+id/date" />


TextView job= (TextView) findViewById(R.id.job);
job.setText(??);

But I don't know how to set the data to the TextView

Thank you

Upvotes: 0

Views: 52

Answers (1)

chiastic-security
chiastic-security

Reputation: 20520

You want to use the org.json library. It will allow you to parse and process your JSON as a JSONObject. Inside that you'll have two strings and a JSONArray, which you can also drill down into.

The library makes it all very easy.

Once you have your JSONObject obj, call

obj.getJSONArray("history");

to get the next level down; then iterate through that, looking at the objects it contains, on each one calling

historyElt.getString("job");

Upvotes: 1

Related Questions