如何以 Json 格式从 Azure blob 检索 blob 数据?
how to retrieve blob data from Azure blob in Json format?
我已将 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?
}
}
how to get azure blob data in the form of JSON?
您可以尝试 CloudBlockBlob.DownloadText
方法将 blob 内容下载为文本,然后使用 Json.Net 的 JsonConvert
将字符串序列化到您的客户对象中。例如,类似于以下内容:
var customerData = blob.DownloadText();
var customer = JsonConvert.DeserializeObject<Customer>(customerData);
我已将 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?
}
}
how to get azure blob data in the form of JSON?
您可以尝试 CloudBlockBlob.DownloadText
方法将 blob 内容下载为文本,然后使用 Json.Net 的 JsonConvert
将字符串序列化到您的客户对象中。例如,类似于以下内容:
var customerData = blob.DownloadText();
var customer = JsonConvert.DeserializeObject<Customer>(customerData);