什么是在android中保存该数据的最合适方式

时间:2015-08-28 14:39:30

标签: java android json database save

我制作的应用会询问用户的教师,部门和成绩,然后显示主题列表。

问题是保存主题的最佳方法是什么,以便检索它们并将其显示给用户。

我尝试过XML,但它不起作用,现在我尝试了JSON,但不确定它是否是存储这类数据的最佳方式?

解答:

  

正如所有人所说,最好的方法是将数据保存在SQLite数据库中。

这是我的JSON的快照

{
  "faculty_engineering": {
    "name": "Engineering",
    "department_prep": {
      "name": "prep",
      "grade_1": {
        "term_1": {
          "subjects": [
            "Math",
            "physics",
            "English",
            "Realisation",
            "subject"
          ]
        },
        "term_2": {
          "subjects": [
            "chemistry",
            "Math",
            "fekh",
            "Geometry",
            "Entag",
            "Mechanics"
          ]
        }
      }
    },
    "department_systems_and_computer_engineering": {
      "name": "Systems and computer engineering",
      "grade_1": {
        "term_1": {
          "subjects": [
            "Programming",
            "Electronics",
            "Math",
            "Circuits",
            "Measure",
            "English"
          ]
        },
        "term_2": {
          "subjects": [
            "Algorithms",
            "Electronics",
            "Math",
            "Fields",
            "Religious subject"
          ]
        }
      },
      "grade_2": {
        "term_1": {
          "subjects": [
            "Math",
            "Integrated circuits",
            "Systems and signals",
            "machines  VHDL",
            "Numerical Analysis",
            "Object-oriented programming",
            "Tests",
            "Realisation subject"
          ]
        },
        "term_2": {
          "subjects": [
            "Math",
            "Logical circuits",
            "Automatic Control",
            "Electric machines",
            "Religious subjects",
            "Realisation subject"
          ]
        }
      },
      "grade_3": {
        "term_1": {
          "subjects": [
            "Math",
            "Communications systems",
            "Electronics",
            "Religious subjects",
            "Operating system",
            "Digital Control",
            "Tests ",
            "Transition systems and mechanisms ",
            "Power electric systems ",
            "Realisation subject"
          ]
        },
        "term_2": {
          "subjects": [
            "Databases",
            "Microprocessors",
            "Administration and engineering projects",
            "Sensors of adapters",
            "Religious subjects",
            "Realisation subject"
          ]
        }
      },
      "grade_4": {
        "term_1": {
          "subjects": [
            "Special computer subject",
            "Tests",
            "Engineering programming",
            "Intelligent Systems",
            "Computer architecture",
            "Interpreters",
            "Advanced software",
            "Realisation subject"
          ]
        },
        "term_2": {
          "subjects": [
            "Algorithms",
            "Advanced software",
            "Computer architecture",
            "Interpreters",
            "Realisation subject"
          ]
        }
      }
    },
    "department_": {
      "name": "",
      "grade_1": {
        "term_1": {
          "subjects": [
          ]
        },
        "term_2": {
          "subjects": [
          ]
        }
      },
      "grade_2": {
        "term_1": {
          "subjects": [
          ]
        },
        "term_2": {
          "subjects": [
          ]
        }
      },
      "grade_3": {
        "term_1": {
          "subjects": [
          ]
        },
        "term_2": {
          "subjects": [
          ]
        }
      },
      "grade_4": {
        "term_1": {
          "subjects": [
          ]
        },
        "term_2": {
          "subjects": [
          ]
        }
      }
    }
  }
}

4 个答案:

答案 0 :(得分:2)

如果要查询的数据不在远程服务器上,那么您可以使用Android sqlite数据库来保存和获取数据。

答案 1 :(得分:1)

也许您应该使用SQLite数据库: https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html

JSON和XML更有可能用于传输数据,例如使用网络。

答案 2 :(得分:1)

您可以使用它在Android和iOS之间兼容的https://realm.io/。 它更简单快速。

希望它有所帮助。

答案 3 :(得分:0)

如果您想要离线存储,请转到SQLite。

如果你想要云存储,那就选择Google Firebase,因为它可以提供良好的实施抽象,相当大的存储空间和同步连接。