有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何获取特定用户或学生的JSON

我目前正在进行大学最后一年的项目

大学会为我提供学生所需的一切

现在,例如,如果一名学生要使用注册号和密码登录应用程序,那么我将如何通过JSON验证该用户,以及如何获取特定用户数据以向他/她显示他们的成绩单等

我知道如何从互联网上获取简单的json

任何人都可以分享一些想法

谢谢


共 (2) 个答案

  1. # 1 楼答案

    您可以使用服务器并托管它

    You can use Retrofit for making API Calls.

    1. Open a Login Activity to the Student and ask the student to enter username and password into the form.
    2. Convert the data into JSON using GSON CONVERTERS which are a part of Retrofit Library.
    3. POST the data to you API link.
    4. After getting the data on your server check the username and password in your database and return the response as details of the Student as JSON Data for the same.

    或(由于缺乏安全性,不建议使用)

    1. Add your JSON Data into your Application as HardCoded String.
    2. Create a class with all the fields from JSON data and convert the String to Class Object by using:

      import com.google.gson.Gson;
      Gson gson = new Gson();
      String json_string = JSON_DATA_STRING;
      ClassModel model = gson.fromJson(json_string,ClassModel.class); 
      

      If its an array of JSON Objects you can use:

      ClassModel[] model = gson.fromJson(json_string,ClassModel[].class);
      
    3. Now model contains all your JSON data as Java Class Object.

    4. After getting username and password from Student you can search the model for this username and password and show the details from the Java Class Object.