且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用SDK在Azure函数中将Azure Blob存储到JSON

更新时间:2023-02-09 08:50:47

将其弄清楚了.最后,这是一个非常简单的修复程序:

figured it out. In the end it was a quite simple fix:

我必须确保blob中的每个json条目少于1024个字符,否则它将创建新行,从而使阅读行有问题.

I had to make sure each json entry in the blob was less than 1024 characters, or it would create a new line, thus making reading lines problematic.

遍历每个blob文件,读取并添加到列表的代码如下:

The code that iterates through each blob file, reads and adds to a list is a follows:

data = BlockBlobService(account_name='accname', account_key='key')
generator = data.list_blobs('collection')

dataloaded = []
for blob in generator:
loader = data.get_blob_to_text('collection',blob.name)
trackerstatusobjects = loader.content.split('\n')
for trackerstatusobject in trackerstatusobjects:
    dataloaded.append(json.loads(trackerstatusobject))

由此,您可以添加到数据框并执行您想做的任何事情:) 希望这对有人遇到类似问题的人有所帮助.

From this you can add to a dataframe and do what ever you want :) Hope this helps if someone stumbles upon a similar problem.