I have a JSON file saved on disk that looks like this:
{
"author": [
"Mario Vargas Llosa",
"Maria Duenas",
"Liviu Rebreanu",
"Liviu Rebreanu"
],
"nameBook": [
"Eroul discret",
"Iubirile croitoresei",
"Ion",
"Ion"
],
"priceBook": [
34,
28,
40,
40
],
"publisherBook": [
"Humanitas",
"Polirom",
"Humanitas",
"Dacia"
],
"idBook": [
1,
2,
3,
4
]
}
Then I have the following Java code:
FileReader reader = new FileReader(filePath);
JSONParser jsonParser = new JSONParser();
JSONObject jsonObject = (JSONObject) jsonParser.parse(reader);
JSONArray idBookJ = (JSONArray) jsonObject.get("idBook");
JSONArray nameBookJ = (JSONArray) jsonObject.get("nameBook");
JSONArray authorJ = (JSONArray) jsonObject.get("author");
JSONArray publisherBookJ = (JSONArray) jsonObject.get("publisherBook");
JSONArray priceBookJ = (JSONArray) jsonObject.get("priceBook");
Now I need to sort the contents of the tag publisherBookin alphabetical order, after the first letter of the word, using Bubble Sort. I know this is not the most amazing programming problem, but I am stuck in handling strings from JSONArray as ... Strings.
source
share