12

I have stored json data format in azure blob storage, Now want to retrieve that data from azure blob in the form of json.

I tried like following

 //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?

1 Answer 1

16

You could try CloudBlockBlob.DownloadText method to download the blob contents as text and then use Json.Net's JsonConvert to serialize the string into your customer object. For example, something like the following:

            var customerData = blob.DownloadText();
            var customer = JsonConvert.DeserializeObject<Customer>(customerData);
Sign up to request clarification or add additional context in comments.

3 Comments

thanks but how can i convert that json data into Customer object :( because that data is of customer object
Updated my answer. HTH.
perfect i was bit confused about to use JsonConvert.DeserializeObject directly but you made it simple :) thanks a lot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.