i已将JSON数据格式存储在Azure Blob存储中,现在想以Json的形式从Azure Blob中检索该数据。
我尝试了喜欢
//get all blob from contrainer
var storageAccount = CloudStorageAccount.Parse("connection string");
var blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("tablesblob");
foreach (IListBlobItem item in container.ListBlobs(null, false))
{
if (item.GetType() == typeof(CloudBlockBlob))
{
CloudBlockBlob blob = (CloudBlockBlob)item;
var ms = new MemoryStream();
//blob.DownloadToStream(ms); how to get blob data in the form of JSON?
}
}
如何以JSON的形式获取Azure Blob数据?
您可以尝试使用CloudBlockBlob.DownloadText
方法将BLOB内容下载为文本,然后使用JSON.NET的JsonConvert
将字符串序列化到您的客户对象中。例如,类似以下内容:
var customerData = blob.DownloadText();
var customer = JsonConvert.DeserializeObject<Customer>(customerData);