'How to parse json array in retrofit with no parameter name?
I have a json array of PDF files. What i need is to parse the pdf file via indexes, as there are no parameter name, just a value as PDF file. You can see my PDF file:
@Override
public void onResponse(JSONObject response) {
// response
Gson gson = new Gson() ;
MagazineResponseModel bookResponseModel;
bookResponseModel = gson.fromJson(response.toString(),MagazineResponseModel.class);
listGridViewBooks.addAll(bookResponseModel.getBooks());
mGridView.setAdapter(new MagazineGridViewAdapter(getActivity(),
R.layout.custom_books_view, listGridViewBooks));
}
Here is the example JSON response, i want to parse the first item of "file" array. Does any body have an idea? Let me know if you need more explanation.
{"file": [
"file1.pdf",
"file2.pdf"
] }
Solution 1:[1]
JSONArray fileArray = bookObject.getJSONArray("file");
for (int j = 0; j<fileArray.length(); j++){
JSONArray nestedFileArray = fileArray.getJSONArray(j);
YOUR_MODEL.setFile(nestedFileArray.getString(YOUR_FILE_POSITION));}
I re-write the @droiDev answer for better results
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kashif Ahmad |
