我已将zson数据格式存储在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数据?
答案 0 :(得分:11)
您可以尝试CloudBlockBlob.DownloadText
方法将blob内容下载为文本,然后使用Json.Net的JsonConvert
将字符串序列化到您的客户对象中。例如,类似以下内容:
var customerData = blob.DownloadText();
var customer = JsonConvert.DeserializeObject<Customer>(customerData);