I am trying to get a list of images in a json file that I have on my web server with my Android app. But they are not readable, I must have made a mistake, probably in my json file.
I am trying to create a .Json file that my application can read, one of my experimental JSON files is listed below, but it does not work.
Since I am not very versed in Json, I was wondering if anyone else could find out how to create a JSON file that my application can handle.
My experimental json file:
{
"Wallpaper": [
{
"id": "1",
"title": "Clouds",
"thumburl": "http://url.com/images/Pages/Apps/apps.png",
"previewurl": "http://url.com/images/Pages/Apps/apps.png",
"url": "http://url.com/images/Pages/Apps/apps.png",
"text": "Sky"
}
]
}
And my code is:
import someimportsandotherstuff
import de.dan_nrw.android.scroid.Wallpaper;
public final class JsonWallpaperParser implements IWallpaperParser {
JsonWallpaperParser() {
super();
}
@Override
public List<Wallpaper> parse(String data) throws ParseException {
try {
JSONArray array = new JSONArray(data);
List<Wallpaper> wallpapers = new ArrayList<Wallpaper>();
for (int i = 0; i < array.length(); i++) {
JSONObject jsonWallpaper = array.getJSONObject(i);
wallpapers.add(new Wallpaper(jsonWallpaper.getString("id"),
jsonWallpaper.getString("title"),
URI.create(jsonWallpaper.getString("thumburl")),
URI.create(jsonWallpaper.getString("previewurl")),
URI.create(jsonWallpaper.getString("url")),
jsonWallpaper.getString("text")));
}
return wallpapers;
}
catch (JSONException ex) {
throw new ParseException(ex.getMessage(), 0);
}
}
}
Any help is appreciated!
source
share