Объект Android Java ArrayListJAVA

Программисты JAVA общаются здесь
Anonymous
Объект Android Java ArrayList

Сообщение Anonymous »

Пытаясь изучить пример Android-приложения в Android Studio, я нашел ArrayList.
В режиме отладки значения этого массива такие, как показано ниже (с использованием инструмента просмотра среды IDE)
Я не совсем понимаю, как распознать каждый элемент массива.
Я бы признателен за любую помощь.
Список составлен, как показано ниже (из файла JSON).
public static List getPrintDataFromJson(Context context, String jsonFileName, int copies, float multiple) {
try {
String jsonContent = AssetJsonReader.readJsonFromAssets(context, jsonFileName,
error -> Log.e(TAG, "Json not found: " + jsonFileName + ", error: " + error));

if (jsonContent == null || jsonContent.isEmpty()) {
Log.e(TAG, "JSON is empty: " + jsonFileName);
return null;
}

return parseJsonToPrintData(jsonContent, copies, multiple);

} catch (Exception e) {
Log.e(TAG, "Cannot get data from Json: " + jsonFileName, e);
return null;
}
}

and...

private static List parseJsonToPrintData(String jsonContent, int copies, float multiple) {
try {
List
templates = null;

try {
PrintTemplate[] templateArray = JsonProcessor.GSON_INSTANCE.fromJson(jsonContent, PrintTemplate[].class);
if (templateArray != null && templateArray.length > 0) {
templates = new ArrayList();
Collections.addAll(templates, templateArray);
}
} catch (Exception e) {
try {
PrintTemplate template = JsonProcessor.GSON_INSTANCE.fromJson(jsonContent, PrintTemplate.class);
if (template != null) {
templates = new ArrayList();
templates.add(template);
}
} catch (Exception ex) {
Log.e(TAG, "Unable to parse JSON as a PrintTemplate object or array", ex);
return null;
}
}

if (templates == null || templates.isEmpty()) {
Log.e(TAG, "There is no valid template data in the JSON.");
return null;
}

List processedJsonData = JsonProcessor.processTemplateList(templates);
int templateLength = templates.size();
List infoWrappers = new ArrayList();

for (int i = 0; i < templateLength; i++) {
infoWrappers.add(createPrinterImageProcessingInfoWrapper(templates.get(i), copies, multiple));
}
List processedInfoData = JsonProcessor.processInfoWrapperList(infoWrappers);

List printData = new ArrayList();
printData.add(new ArrayList(processedJsonData));
printData.add(new ArrayList(processedInfoData));

return printData;

} catch (JsonSyntaxException e) {
Log.e(TAG, "JSON syntax error", e);
return null;
} catch (Exception e) {
Log.e(TAG, "Parsing JSON content failed to print data", e);
return null;
}
}


и результат в списке будет таким, как показано ниже.
{
"width" : 40.0,
"height" : 20.0,
"rotate" : 0,
"background" : "",
"backgroundImage" : "",
"elements" : [ {
"type" : "barcode",
"x" : 2.0,
"y" : 2.0,
"width" : 36.0,
"height" : 16.0,
"rotate" : 0,
"codeType" : 20,
"value" : "6942141752896",
"fontSize" : 3.200000047683716,
"textHeight" : 3.200000047683716,
"textPosition" : 0,
"zIndex" : 0,
"isTitle" : 0
},{
"type" : "text",
"x" : 2.0,
"y" : 2.0,
"width" : 36.0,
"height" : 7.400000095367432,
"rotate" : 0,
"value" : "Certificate",
"fontCode" : "",
"fontFamily" : "",
"fontSize" : 5.599999904632568,
"textAlignHorizonral" : 1,
"textAlignVertical" : 1,
"lineMode" : 9,
"letterSpacing" : 0.0,
"lineSpacing" : 1.0,
"typesettingMode" : 1,
"colorReverse" : 0,
"zIndex" : 101,
"wordSpacing" : 0,
"lineBreakMode" : 1,
"isTitle" : 0,
"fontStyle" : [ "bold" ]
} ]

Вернуться в «JAVA»