我正在使用azure blob存儲來存儲JSON文件,並在我的代碼中使用C#API下載它。CloudBlockBlob.DownloadTextAsync返回無效文本
當我下載文本文件的內容並嘗試使用JsonConvert對其進行反序列化時,出現錯誤(Visual Studio JSON可視化工具也顯示文本錯誤)。但是,如果我複製文本並粘貼到JSONLint.com中,它看起來很好。另外,如果我手動從Azure存儲下載文件並在代碼中讀取文件,則它反序列化就好了。我使用C#API下載時遇到無效數據的任何想法?
var storageAccount = CloudStorageAccount.Parse(connectionString);
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(containerName);
var blob = container.GetBlockBlobReference(folderAndFileName);
var text = await blob.DownloadTextAsync();
var obj = JsonConvert.DeserializeObject(text);
// Exception: "Unexpected character encountered while parsing value: . Path '', line 0, position 0."
注:我通過PowerShell的上傳文件:
$blobProperties = @{"ContentType" = "application/json"};
Set-AzureStorageBlobContent -Container $containerName -File $LocalFilePath -Blob $RemoteBlobName -BlobType "Block" -Properties $blobProperties
您的代碼對我來說確實很好。您能否告訴您正在使用的存儲客戶端庫的版本?另外,您是否可以分享您上傳的JSON文件?我想嘗試使用該文件。 –