Мой код выглядит ужасно, и я хочу сделать это лучше.java array with void/methods
if (e == null && !result.isJsonNull() && result.get("code").getAsInt() == 200) {
JsonArray array = result.get("data").getAsJsonObject().get("products").getAsJsonArray();
ProductDAO productDAO = new ProductDAO(getApplicationContext());
for (int i = 0; i < array.size(); i++) {
Product product = new Product();
if (!isProduct(array.get(i).getAsJsonObject().get("id").getAsString())) {
if (!array.get(i).getAsJsonObject().get("_vat_amount").isJsonNull() && !array.get(i).getAsJsonObject().get("_vat_amount").toString().equals("")) {
product.setVatAmount(array.get(i).getAsJsonObject().get("_vat_amount").getAsDouble());
}
if (!array.get(i).getAsJsonObject().get("_vat_rate").isJsonNull() && !array.get(i).getAsJsonObject().get("_vat_rate").toString().equals("")) {
product.setVatRate(array.get(i).getAsJsonObject().get("_vat_rate").getAsDouble());
}
if (!array.get(i).getAsJsonObject().get("_vat_rate_s").isJsonNull() && !array.get(i).getAsJsonObject().get("_vat_rate_s").toString().equals("")) {
product.setVatRateS(array.get(i).getAsJsonObject().get("_vat_rate_s").getAsString());
}
if (!array.get(i).getAsJsonObject().get("brutto_value").isJsonNull() && !array.get(i).getAsJsonObject().get("brutto_value").toString().equals("")) {
product.setBruttoValue(array.get(i).getAsJsonObject().get("brutto_value").getAsDouble());
}
if (!array.get(i).getAsJsonObject().get("count").isJsonNull() && !array.get(i).getAsJsonObject().get("count").toString().equals("")) {
product.setCount(array.get(i).getAsJsonObject().get("count").getAsDouble());
}
if (!array.get(i).getAsJsonObject().get("id").isJsonNull() && !array.get(i).getAsJsonObject().get("id").toString().equals("")) {
product.setFinettoID(array.get(i).getAsJsonObject().get("id").getAsInt());
}
if (!array.get(i).getAsJsonObject().get("lp").isJsonNull() && !array.get(i).getAsJsonObject().get("lp").toString().equals("")) {
product.setLp(array.get(i).getAsJsonObject().get("lp").getAsInt());
}
if (!array.get(i).getAsJsonObject().get("name").isJsonNull() && !array.get(i).getAsJsonObject().get("name").toString().equals("")) {
product.setName(array.get(i).getAsJsonObject().get("name").getAsString());
}
if (!array.get(i).getAsJsonObject().get("netto_value").isJsonNull() && !array.get(i).getAsJsonObject().get("netto_value").toString().equals("")) {
product.setNettoValue(array.get(i).getAsJsonObject().get("netto_value").getAsDouble());
}
if (!array.get(i).getAsJsonObject().get("price").isJsonNull() && !array.get(i).getAsJsonObject().get("price").toString().equals("")) {
product.setPrice(array.get(i).getAsJsonObject().get("price").getAsDouble());
}
if (!array.get(i).getAsJsonObject().get("unit").isJsonNull() && !array.get(i).getAsJsonObject().get("unit").toString().equals("")) {
product.setUnit(array.get(i).getAsJsonObject().get("unit").getAsString());
}
productDAO.save(product);
}
}
Есть ли способ создать массив с помощью void/methods (seters)? Я могу разрезать этот json. Это будет лучше. Но я хочу сделать это лучше.
Поскольку у вас нет проблемы, https://codereview.stackexchange.com/ может быть лучше. – Drazisil
О, мой плохой. В следующий раз я напишу в хорошем месте. – RogOnion