【问题标题】:FileInputStream to Json in Xamarin AndroidXamarin Android 中的 FileInputStream 到 Json
【发布时间】:2019-08-08 09:54:00
【问题描述】:

我有一个来自 Android Intent 的 FileInputStream

    var parcelFileDescriptor = this.ContentResolver.OpenFileDescriptor(extras, "r");
    var fileInputStream = new FileInputStream(parcelFileDescriptor.FileDescriptor);

我知道生成的文件是一个 json 文件,我该如何从 FileInputStream 转到 Json?我假设我需要从 FileInputStream 到 Stream,然后到 Json,但不知道该怎么做

谢谢

【问题讨论】:

标签: android xamarin.android


【解决方案1】:

我是如何解决它的

      var parcelFileDescriptor = this.ContentResolver.OpenFileDescriptor(extras, "r");
      var fileInputStream = new FileInputStream(parcelFileDescriptor.FileDescriptor);

      StringBuffer fileContent = new StringBuffer("");

      byte[] buffer = new byte[1024];
      int n;

      while ((n = fileInputStream.Read(buffer)) != -1)
      {
        fileContent.Append(new String(buffer, 0, n));
      }

      var result = Newtonsoft.Json.JsonConvert.DeserializeObject(fileContent.ToString());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多