小编Dor*_* Do的帖子

有什么方法可以将google protobuf消息转换为带有缩进的json?

我需要使用 C#将Google protobuf IMessage 对象保存到 json 文件中。这是示例代码:

using (var input = File.OpenRead(protodatFile)) 
{
    string jsonString = null;
    message.MergeFrom(input); //read message from protodat file
    JsonFormatter formater = new JsonFormatter(
        new JsonFormatter.Settings(false));
    jsonString = formatter.Format(message);
    System.IO.File.WriteAllText(jsonFile, jsonString);
}
Run Code Online (Sandbox Code Playgroud)

这使用JsonFormatter来自 Google Protobuf 库的

问题:所有 json 内容都存储在一行中。当文件很大(> 50 MB)时,很难在文本编辑器中打开/查看。

在这里制作缩进 jsonFile 的最佳方法是什么?

c# indentation protocol-buffers

8
推荐指数
1
解决办法
4908
查看次数

标签 统计

c# ×1

indentation ×1

protocol-buffers ×1