In my app I've to parse this JSON:
programs.json
{
"programs": {
"program": [
{
"programNumber": "1",
"imgURL": "http://www.photovideolife.com/userfiles/Placeholder%2001.jpg",
"description": "Lorem ipsum dolor sit er elit",
"episode": [
{
"pN": "1",
"episodeNumber": "1",
"transmissionName": "Titolo",
"date": "29 Giu 2013",
"time": "14:30",
"channel": "Real Time",
"channelLogo": "https://lh6.googleusercontent.com/-XSh-9ngYJu4/ThiY-xl2EeI/AAAAAAAABmc/iz04VpL5hOs/s800/realtime.png"
},
{
"pN": "1",
"episodeNumber": "1",
"transmissionName": "Titolo",
"date": "29 Giu 2013",
"time": "16:30",
"channel": "DMAX",
"channelLogo": "http://tv.zam.it/canali/dmax.png"
},
{
"pN": "1",
"episodeNumber": "2",
"transmissionName": "Titolo",
"date": "01 Lug 2013",
"time": "14:30",
"channel": "Real Time",
"channelLogo": "https://lh6.googleusercontent.com/-XSh-9ngYJu4/ThiY-xl2EeI/AAAAAAAABmc/iz04VpL5hOs/s800/realtime.png"
},
{
"pN": "1",
"episodeNumber": "2",
"transmissionName": "Titolo",
"date": "01 Lug 2013",
"time": "16:30",
"channel": "DMAX",
"channelLogo": "http://tv.zam.it/canali/dmax.png"
}
]
},
{
"programNumber": "2",
"imgURL": "http://mesa.umich.edu/files/mesa/field/image/placeholder2.png",
"description": "Lorem ipsum dolor sit er elit",
"Episode": [
{
"pN": "2",
"episodeNumber": "1",
"transmissionName": "Titolo 1",
"date": "30 Giu 2013",
"time": "13:30",
"channel": "Real Time",
"channelLogo": "https://lh6.googleusercontent.com/-XSh-9ngYJu4/ThiY-xl2EeI/AAAAAAAABmc/iz04VpL5hOs/s800/realtime.png"
},
{
"pN": "2",
"episodeNumber": "1",
"transmissionName": "Titolo 1",
"date": "30 Giu 2013",
"time": "18:30",
"channel": "DMAX",
"channelLogo": "http://tv.zam.it/canali/dmax.png"
},
{
"pN": "2",
"episodeNumber": "2",
"transmissionName": "Titolo 1",
"date": "01 Lug 2013",
"time": "13:30",
"channel": "Real Time",
"channelLogo": "https://lh6.googleusercontent.com/-XSh-9ngYJu4/ThiY-xl2EeI/AAAAAAAABmc/iz04VpL5hOs/s800/realtime.png"
},
{
"pN": "2",
"episodeNumber": "2",
"transmissionName": "Titolo 1",
"date": "01 Lug 2013",
"time": "18:30",
"channel": "DMAX",
"channelLogo": "http://tv.zam.it/canali/dmax.png"
}
]
},
{
"programNumber": "3",
"imgURL": "http://wp.contempographicdesign.com/wp_paramount/wp-content/themes/paramount/images/image_placeholder_lrg.jpg",
"description": "Lorem ipsum dolor sit er elit",
"Episode": [
{
"pN": "3",
"episodeNumber": "1",
"transmissionName": "Titolo 2",
"date": "30 Giu 2013",
"time": "10:30",
"channel": "Real Time",
"channelLogo": "https://lh6.googleusercontent.com/-XSh-9ngYJu4/ThiY-xl2EeI/AAAAAAAABmc/iz04VpL5hOs/s800/realtime.png"
},
{
"pN": "3",
"episodeNumber": "1",
"transmissionName": "Titolo 2",
"date": "30 Giu 2013",
"time": "17:30",
"channel": "DMAX",
"channelLogo": "http://tv.zam.it/canali/dmax.png"
},
{
"pN": "3",
"episodeNumber": "2",
"transmissionName": "Titolo 2",
"date": "01 Lug 2013",
"time": "10:30",
"channel": "Real Time",
"channelLogo": "https://lh6.googleusercontent.com/-XSh-9ngYJu4/ThiY-xl2EeI/AAAAAAAABmc/iz04VpL5hOs/s800/realtime.png"
},
{
"pN": "3",
"episodeNumber": "2",
"transmissionName": "Titolo 2",
"date": "01 Lug 2013",
"time": "17:30",
"channel": "DMAX",
"channelLogo": "http://tv.zam.it/canali/dmax.png"
}
]
}
]
}
}
I wanted to create some objects to store data from this JSON file so I used the Gson library to make this parsing very easy. I'm having trouble to create objects by using this library, I created 4 objects:
- EpisodeData in which I store this informations (pN, episodeNumber, date, time, channel and channelLogo)
- Episode it's an array of EpisodeData
- Program it's an array of Episode
- Programs in which I store the array Program
Here's the code of the objects:
EpisodeData.java
public class EpisodeData implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
public String pN, episodeNumber, transmissionName, date, time, channel, channelLogo;
}
Episode.java
public class Episode implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
public EpisodeData[] episodeData;
}
Program.java
public class Program implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
public Episode[] episode;
}
Programs.java
public class Programs implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
public Program program;
}
So I made the connection (with AsyncHttpClient) to download the JSON file from a server and I started to parse it, but I'm having trouble. I post here the code snippet:
public void onSuccess(String json) {
super.onSuccess(json);
Gson decoder = new Gson();
Programs programs = decoder.fromJson(json, Programs.class);
Log.d("PROGRAMS", "" + programs.program);
}
Why I can't access to Episode and EpisodeData? Why when I try to log programs.program it returns null?
I hope you can help me to find a solution for this issue Thank you
-. I saw that in JSON I'veProgramsandProgramand in my java class I'veprogramsandprogramso I edited my JSON so:Programs -> programsandProgram -> program, but still the same, when I write thisLog.d("PROGRAMS", "" + programs.program);it shows me null... Why? I've update my JSON in my question