简体   繁体   English

为什么json文件上传到azure blob存储c#时出现Rare characters?

[英]Why does Rare characters appears when json file is uploaded to azure blob storage c#?

I am trying to update a JSON file which is located in azure blob storage.我正在尝试更新位于 azure blob 存储中的 JSON 文件。 when the program does the put call the saved file looks like this:当程序执行 put 调用时,保存的文件如下所示:

Zona de especial protección特殊保护区

the accents and other characters are the matter, but that only happens when I download the file from the azure UI interface if I do a get from postman, that does not happen.重音和其他字符是问题,但只有当我从 azure UI 界面下载文件时才会发生,如果我从 postman 获取文件,那不会发生。 this is my code:这是我的代码:

SemanticDictionaryContent semanticDictionaryContent = new SemanticDictionaryContent()
        {
            Name = entity.Id + JSON_EXTENSION,
            Content = BinaryData.FromObjectAsJson(entity)

        };
  1. Create a storage account in azure.在 azure 中创建一个存储帐户。

在此处输入图像描述

  1. Create a container in azure.在 azure 中创建一个容器。

在此处输入图像描述

  1. Uploaded a Json file to a container using the below code.使用以下代码将Json文件上传到容器。

I have used the below approach in Uploading / downloading / editing the Json file.我在上传/下载/编辑 Json 文件时使用了以下方法。

 public static bool Upload()
        {
            try
            {
            var containerName = "mycontainer";
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConnectionSting);
            CloudBlobClient client = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = client.GetContainerReference(containerName);
                
            var isCreated = container.CreateIfNotExists();
            container.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
            using (FileStream fileStream = File.Open(@"C:\Tools\local.settings.json", FileMode.Open))
             {
               using (MemoryStream memoryStream = new MemoryStream())
                 {
                   memoryStream.Position = 0;
                   fileStream.CopyTo(memoryStream);
                   var fileName  = "local.settings.json";
                   CloudBlockBlob blob = container.GetBlockBlobReference(fileName);
                   string mimeType = "application/unknown";
                   string ext = (fileName.Contains(".")) ? System.IO.Path.GetExtension(fileName).ToLower() : "." + fileName;
                   Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
                   if (regKey != null && regKey.GetValue("Content Type") != null) mimeType = regKey.GetValue("Content Type").ToString();
                   memoryStream.ToArray();
                   memoryStream.Seek(0, SeekOrigin.Begin);
                   blob.Properties.ContentType = mimeType;
                   blob.UploadFromStream(memoryStream);
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                throw;
            }
        }

Uploaded Json file上传Json文件在此处输入图像描述

  1. Updated the Json file in azure and uploaded it using the below code.更新了 azure 中的 Json 文件,并使用以下代码上传。
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConnectionSting);
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");
            CloudBlockBlob jsonBlob = container.GetBlockBlobReference("local.settings.json");
            string jsonText = jsonBlob.DownloadText();

            dynamic jsonData = JsonConvert.DeserializeObject(jsonText);
            jsonData.property1 = "Property1";
            jsonData.property2 = "Property2";
            jsonBlob.UploadText(JsonConvert.SerializeObject(jsonData));
  1. And downloaded the Json file from azure manually and do not find any special characters.并手动从azure下载了Json文件,没有发现任何特殊字符。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure function C#:写入 Azure 上的块 blob(csv 文件)存储帐户创建了两个版本的 blob - Azure function C#: Writing to Block blob (csv file) on Azure Storage Account creates two versions of the blob Azure 存储 Blob:上传的 CSV 文件显示零字节 - Azure Storage Blob: Uploaded CSV file shows zero bytes Azure 使用标签的 blob 存储搜索 c# - Azure blob storage search using tags c# 如何使用 Blazor 将大文件上传到 WebAPI (C#) 并将其存储到 Azure Blob 存储中 - How to upload large file using Blazor to WebAPI (C#) and store it into Azure Blob storage Azure Blob 存储文件访问 - Azure Blob Storage file access az storage blob download 在 Azure 管道中运行时不下载文件 - az storage blob download not downloading file when run in Azure Pipelines 将文件写入 blob 存储并使用 C# 保存 SaS URL - Write file to blob storage and save the SaS URL using C# 在 Azure Blob 存储中查找音频文件 - Seek in Audio File in Azure Blob Storage 使用 UWP C# (mediaCapture) 捕获网络摄像头并保存到 azure blob 存储中 - Capture webcamera and save into azure blob storage using UWP C# (mediaCapture) 如何从存储在Azure blob存储中的json文件中获取数据 - How to get data from json file stored in Azure blob storage in react
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM