Proto3 定义返回 C# map<string, List<dynamic>> 类型数据
<p>在 Proto3 中,可以使用 'map' 类型来定义键值对,其中键的类型为 'string',值的类型为 'repeated',即一个列表。在 C# 中,由于没有动态类型,可以使用 'List<object>' 来代替 'List<dynamic>'。</p>
<p>下面是一个示例:</p>
<pre><code>syntax = "proto3";
message MyResponse {
map<string, repeated object> my_map = 1;
}
</code></pre>
<p>在 C# 中生成的代码中,'my_map' 的类型为 'Dictionary<string, List<object>>'。可以通过以下方式访问:</p>
<pre><code class="language-csharp">MyResponse response = ...;
List<object> myList = response.my_map['myKey'];
</code></pre>
原文地址: https://www.cveoy.top/t/topic/nwvF 著作权归作者所有。请勿转载和采集!