VB.NET 是否可以将 JSON 数据导出到 JSON 格式的文件中?

Rip*_*les 2 vb.net json

我想知道是否可以使用 GET 请求从服务器获取 JSON 文本,然后将该数据以 JSON 格式输出到本地文件中。

我似乎唯一能找到的是这个电话:

File.WriteAllText(AgentWorkingDirectory & "\json.txt", JsonConvert.SerializeObject(return_message))`
Run Code Online (Sandbox Code Playgroud)

这似乎只给了我一行连续的未格式化的文本。

所以代替这个:

{
    "AlertingRules":[
        {  
            "RuleId":1,
            "Name":"Unprocessed Directory",
            "RuleConditions":[
                {  
                    "Name":"FileCount",
                    "FileName":"",
                    ...
Run Code Online (Sandbox Code Playgroud)

我明白了:

{"AlertingRules":[{"RuleId":1,"Name":"Unprocessed Directory","RuleConditions":[{"Name":"FileCount","FileName":null,...
Run Code Online (Sandbox Code Playgroud)

Dav*_*dot 5

将格式化参数添加到序列化调用中

File.WriteAllText(AgentWorkingDirectory & "\json.txt",JsonConvert.SerializeObject(return_message, Newtonsoft.Json.Formatting.Indented))
Run Code Online (Sandbox Code Playgroud)

请参阅Json.NET 文档