我可以在哪里上传 json 文件?

where can I upload json file?

我已经写了一个包含数据的 json 文件,我会在 android 中将其发送到 recycleview,但我不知道在哪里可以上传此文件以访问它 android项目

您可以将 JSON 文件存储在您的资产文件夹中……

void saveStringToFile(String path, String content) {
    try {
        File newFile = new File(path);
        newFile.createNewFile();
        FileOutputStream fos = new FileOutputStream(newFile);
        fos.write(content.getBytes());
        fos.flush();
        fos.close();
        Constant.logD("File "+ newFile.getName()+ " is saved successfully at "+ newFile.getAbsolutePath());
    } catch (Exception e) {
        Constant.logE("Unable to save file", e);
    }
}

提及移动 SD 卡中的路径,例如 Environment.getExternalStorageDirectory().getAbsolutePath()+"/" + System.currentTimeMillis()+".jpg" 作为路径

根据您的要求:

  1. 最好的选择是将其托管在(如果有网络服务器的话)
  2. 如果不这样做,请在 GDrive or Dropbox(或提供免费存储的类似托管服务)上共享文件。以只读访问权限共享它,供您的应用读取。

有两种方法可以做到这一点:

  1. 本地存储:您可以在项目本地保存一个JSON文件。 (已被其他人回答)
  2. 上传您的 JSON:您可以在 jsonbin.io 上传您的 JSON,它会生成一个 API,您可以在您的项目中使用它。

您可以将 json 文件放在资产文件夹中,最好的选择是在服务器上托管 json 文件并在您的项目中使用数据 (API)。