如何从JBS格式的Azure blob中检索blob数据?

时间:2015-05-15 10:04:38

标签: json azure json.net azure-storage-blobs

我已将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数据?

1 个答案:

答案 0 :(得分:11)

您可以尝试CloudBlockBlob.DownloadText方法将blob内容下载为文本,然后使用Json.Net的JsonConvert将字符串序列化到您的客户对象中。例如,类似以下内容:

            var customerData = blob.DownloadText();
            var customer = JsonConvert.DeserializeObject<Customer>(customerData);