我需要连接我的 Azure 存储(模拟)并获取存储在其中的文件和目录的 JSON 编码列表。
我用过这个doc连接到我的存储,我可以列出内容。
现在我想知道:是否可以获取我的存储的树木并将其作为 JSON 数组获取?
最佳答案
根据您的代码,您可以创建主 POCO(普通旧 CLR 对象)和子 POCO(普通旧 CLR 对象) - 分别是容器和 Blob。然后,迭代容器并将它们添加到列表中。对于每个容器,迭代 blob 并将它们添加到容器对象中。然后serialize these to JSON以获得您的代表。
或者
您可以使用 BLOB 存储 REST API
GET https://myaccount.blob.core.windows.net/mycontainer?restype=container&comp=list&delimiter=/&maxresults=4
如果您需要将XML结果转换为JSON,您可以使用Newtonsoft的库Using Newtonsoft to convert XML to JSON
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Newtonsoft.Json;
namespace JSonConverter
{
class Program
{
static void Main(string[] args)
{
string xml = "<Test><Name>Test class</Name><X>100</X><Y>200</Y></Test>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
string json = Newtonsoft.Json.JsonConvert.SerializeXmlNode(doc);
Console.WriteLine("XML -> JSON: {0}", json);
Console.ReadLine();
}
}
}
关于c# - .NET WCF 服务获取 Blob 的 JSON 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33955551/