<p>在 Proto3 中,可以使用 'map' 类型来定义键值对,其中键的类型为 'string',值的类型为 'repeated',即一个列表。在 C# 中,由于没有动态类型,可以使用 'List<object>' 来代替 'List<dynamic>'。</p>
<p>下面是一个示例:</p>
<pre><code>syntax = &quot;proto3&quot;;

message MyResponse {
  map&lt;string, repeated object&gt; my_map = 1;
}
</code></pre>
<p>在 C# 中生成的代码中,'my_map' 的类型为 'Dictionary&lt;string, List<object>&gt;'。可以通过以下方式访问:</p>
<pre><code class="language-csharp">MyResponse response = ...;
List&lt;object&gt; myList = response.my_map['myKey'];
</code></pre>
Proto3 定义返回 C# map<string, List<dynamic>> 类型数据

原文地址: https://www.cveoy.top/t/topic/nwvF 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录