【问题标题】:how to retrieve blob data from Azure blob in Json format?如何以 Json 格式从 Azure blob 中检索 blob 数据?
【发布时间】:2015-07-27 05:05:47
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,但我怎样才能将 json 数据转换为客户对象 :( 因为该数据属于客户对象
    • 更新了我的答案。 HTH。
    • 完美 我对直接使用JsonConvert.DeserializeObject 有点困惑,但你让它变得简单:) 非常感谢
    猜你喜欢
    • 1970-01-01
    • 2018-02-18
    • 2016-08-13
    • 2017-10-12
    • 1970-01-01
    • 1970-01-01
    • 2021-11-08
    • 1970-01-01
    • 2021-07-12
    相关资源
    最近更新 更多