Ответы пользователя по тегу Java
  • Что теряет разработчик под Android используя не родную Java, a C# Xamarin?

    Деньги. Сами Microsoft сказали что xamarin для людей которым некуда засунуть денюжку ;)
    Ответ написан
    Комментировать
  • Как хранить данные в классах-структурах в Java?

    Ладно в кратце про gson
    Объект
    public class BookObject implements IDBSerializable{
    
        long id;
        long series_id;
        long publisher_id;
        int published_at_year;
        int page_count;
        int byte_count;
        String title_ru;
        String title_ln;
        String title_il;
        String description;
        String author_first_name_ru;
        String author_last_name_ru;
        String author_first_name_ln;
        String author_last_name_ln;
        String content_preview;
        String content;
        String isbn;
        String apple_product_id;
        Date created;
        Date updated;
        CoverObject cover;
        ArrayList<BookObject> recomendations;
    
        @Override
        public void putToContentValues(ContentValues values) {
            values.put(FIELD_ID, id);
    //        values.put(FIELD_FOREIGN_ID, id);
            values.put(FIELD_SERIES_ID, series_id);
            values.put(FIELD_PUBLISHER_ID, publisher_id);
            values.put(FIELD_YEAR, published_at_year);
            values.put(FIELD_PAGE_COUNT, page_count);
            values.put(FIELD_BYTE_COUNT, byte_count);
            values.put(FIELD_TITLE_RU, title_ru);
            values.put(FIELD_TITLE_LN, title_ln);
            values.put(FIELD_TITLE_IL, title_il);
            values.put(FIELD_DESCRIPTION, description);
            values.put(FIELD_AUTHOR_FIRST_NAME_RU, author_first_name_ru);
            values.put(FIELD_AUTHOR_LAST_NAME_RU, author_last_name_ru);
            values.put(FIELD_AUTHOR_FIRST_NAME_LN, author_first_name_ln);
            values.put(FIELD_AUTHOR_LAST_NAME_LN, author_last_name_ln);
            values.put(FIELD_ISBN, isbn);
            values.put(FIELD_PRODUCT_ID, apple_product_id);
            values.put(FIELD_CREATED, created.getTime());
            values.put(FIELD_UPDATED, updated.getTime());
            values.put(FIELD_BOOK, content); // book url
            values.put(FIELD_BOOK_PREVIEW, content_preview); // book preview url
            values.put(FIELD_COVER_IMAGE, cover.original); // book cover url
            values.put(FIELD_COVER_PREVIEW_IMAGE, cover.preview); // book cover preview url
        }
    
        public BookObject() {
        }
    
        public BookObject(Cursor cursor){
                this.id = cursor.getLong(cursor.getColumnIndex(FIELD_ID));
                this.series_id = cursor.getLong(cursor.getColumnIndex(FIELD_SERIES_ID));
                this.publisher_id = cursor.getLong(cursor.getColumnIndex(FIELD_PUBLISHER_ID));
                this.published_at_year = cursor.getInt(cursor.getColumnIndex(FIELD_YEAR));
                this.page_count = cursor.getInt(cursor.getColumnIndex(FIELD_PAGE_COUNT));
                this.byte_count = cursor.getInt(cursor.getColumnIndex(FIELD_BYTE_COUNT));
                this.title_ru = cursor.getString(cursor.getColumnIndex(FIELD_TITLE_RU));
                this.title_ln = cursor.getString(cursor.getColumnIndex(FIELD_TITLE_LN));
                this.title_il = cursor.getString(cursor.getColumnIndex(FIELD_TITLE_IL));
                this.description = cursor.getString(cursor.getColumnIndex(FIELD_DESCRIPTION));
                this.author_first_name_ru = cursor.getString(cursor.getColumnIndex(FIELD_AUTHOR_FIRST_NAME_RU));
                this.author_last_name_ru = cursor.getString(cursor.getColumnIndex(FIELD_AUTHOR_LAST_NAME_RU));
                this.author_first_name_ln = cursor.getString(cursor.getColumnIndex(FIELD_AUTHOR_FIRST_NAME_LN));
                this.author_last_name_ln = cursor.getString(cursor.getColumnIndex(FIELD_AUTHOR_LAST_NAME_LN));
                this.isbn = cursor.getString(cursor.getColumnIndex(FIELD_ISBN));
                this.apple_product_id = cursor.getString(cursor.getColumnIndex(FIELD_PRODUCT_ID));
                this.created = new Date(cursor.getInt(cursor.getColumnIndex(FIELD_CREATED)));
                this.updated = new Date(cursor.getInt(cursor.getColumnIndex(FIELD_UPDATED)));
                this.content = cursor.getString(cursor.getColumnIndex(FIELD_BOOK));
                this.content_preview = cursor.getString(cursor.getColumnIndex(FIELD_BOOK_PREVIEW));
                this.cover = new CoverObject(
                        cursor.getString(cursor.getColumnIndex(FIELD_COVER_IMAGE)),
                        cursor.getString(cursor.getColumnIndex(FIELD_COVER_PREVIEW_IMAGE))
                );
        }
    
        public long getId() {
            return id;
        }
    
        public void setId(long id) {
            this.id = id;
        }
    
        public long getSeries_id() {
            return series_id;
        }
    
        public void setSeries_id(long series_id) {
            this.series_id = series_id;
        }
    
        public long getPublisher_id() {
            return publisher_id;
        }
    
        public void setPublisher_id(long publisher_id) {
            this.publisher_id = publisher_id;
        }
    
        public int getPublished_at_year() {
            return published_at_year;
        }
    
        public void setPublished_at_year(int published_at_year) {
            this.published_at_year = published_at_year;
        }
    
        public int getPage_count() {
            return page_count;
        }
    
        public void setPage_count(int page_count) {
            this.page_count = page_count;
        }
    
        public int getByte_count() {
            return byte_count;
        }
    
        public void setByte_count(int byte_count) {
            this.byte_count = byte_count;
        }
    
        public String getTitle_ru() {
            return title_ru;
        }
    
        public void setTitle_ru(String title_ru) {
            this.title_ru = title_ru;
        }
    
        public String getTitle_ln() {
            return title_ln;
        }
    
        public void setTitle_ln(String title_ln) {
            this.title_ln = title_ln;
        }
    
        public String getTitle_il() {
            return title_il;
        }
    
        public void setTitle_il(String title_il) {
            this.title_il = title_il;
        }
    
        public String getDescription() {
            return description;
        }
    
        public void setDescription(String description) {
            this.description = description;
        }
    
        public String getAuthor_first_name_ru() {
            return author_first_name_ru;
        }
    
        public void setAuthor_first_name_ru(String author_first_name_ru) {
            this.author_first_name_ru = author_first_name_ru;
        }
    
        public String getAuthor_last_name_ru() {
            return author_last_name_ru;
        }
    
        public void setAuthor_last_name_ru(String author_last_name_ru) {
            this.author_last_name_ru = author_last_name_ru;
        }
    
        public String getAuthor_first_name_ln() {
            return author_first_name_ln;
        }
    
        public void setAuthor_first_name_ln(String author_first_name_ln) {
            this.author_first_name_ln = author_first_name_ln;
        }
    
        public String getAuthor_last_name_ln() {
            return author_last_name_ln;
        }
    
        public void setAuthor_last_name_ln(String author_last_name_ln) {
            this.author_last_name_ln = author_last_name_ln;
        }
    
        public String getContent_preview() {
            return content_preview;
        }
    
        public void setContent_preview(String content_preview) {
            this.content_preview = content_preview;
        }
    
        public String getContent() {
            return content;
        }
    
        public void setContent(String content) {
            this.content = content;
        }
    
        public String getIsbn() {
            return isbn;
        }
    
        public void setIsbn(String isbn) {
            this.isbn = isbn;
        }
    
        public String getApple_product_id() {
            return apple_product_id;
        }
    
        public void setApple_product_id(String apple_product_id) {
            this.apple_product_id = apple_product_id;
        }
    
        public Date getCreated() {
            return created;
        }
    
        public void setCreated(Date created) {
            this.created = created;
        }
    
        public Date getUpdated() {
            return updated;
        }
    
        public void setUpdated(Date updated) {
            this.updated = updated;
        }
    
        public CoverObject getCover() {
            return cover;
        }
    
        public void setCover(CoverObject cover) {
            this.cover = cover;
        }
    
        public ArrayList<BookObject> getRecomendations() {
            return recomendations;
        }
    
        public void setRecomendations(ArrayList<BookObject> recomendations) {
            this.recomendations = recomendations;
        }
    
        public static class CoverObject {
    
            String original;
            String preview;
    
            CoverObject() {
            }
    
            CoverObject(String original, String preview) {
                this.original = original;
                this.preview = preview;
            }
    
            public String getOriginal() {
                return original;
            }
    
            public void setOriginal(String original) {
                this.original = original;
            }
    
            public String getPreview() {
                return preview;
            }
    
            public void setPreview(String preview) {
                this.preview = preview;
            }
        }
    }

    немного жирный так как в нем еще к БД связь.

    gson
    private ArrayList<BookObject> jsonToBooks(JSONArray json){
    Type mListType = new TypeToken< ArrayList<BookObject>>(){}.getType();
    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd kk:mm:ss").create();
    return gson.fromJson(String.valueOf(json), mListType);
        }


    а ранще я все ручками парсли, а так ПУФФФФ и с jsona готовый массив объектов
    Ответ написан