Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Yaml-如何在单行中编写映射_Yaml_Mapping - Fatal编程技术网

Yaml-如何在单行中编写映射

Yaml-如何在单行中编写映射,yaml,mapping,Yaml,Mapping,我有以下yaml version: "0.1" services: svc: image: test networks: - test_net_1 - test_net_2 - test_net_3 networkMapping: test_net_1: external: true test_net_2: external: true test_net_3: exte

我有以下yaml

version: "0.1"
services: 
  svc: 
    image: test
    networks: 
      - test_net_1
      - test_net_2
      - test_net_3

networkMapping: 
  test_net_1: 
    external: true
  test_net_2: 
    external: true
  test_net_3: 
    external: true
我想在一行中重写networkMapping,如下所示

version: "0.2"
services: 
  svc: 
    image: test
    networks: ['test_net_1', 'test_net_2', 'test_net_3']

networkMapping: {{'test_net_1': {'external': true}}, {'test_net_2': {'external': true}}, {'test_net_3': {'external': true}}}
  
但是当使用lint/parse时,它返回如下结果

version: "0.2"
services: 
  svc: 
    image: test
    networks: 
      - test_net_1
      - test_net_2
      - test_net_3

networkMapping: 
  ? 
    test_net_1': 
      external: true
  : ~
  ? 
    test_net_2: 
      external: true
  : ~
  ? 
    test_net_3: 
      external: true
  : ~
并导致应用程序“无效的映射键:映射[interface{}]interface{}{“test{u net_1”:映射[interface{}]interface{}{“external”:true}}}”中出错

我用双引号而不是单引号检查,也没有引号。但是没有运气:(

我们可以通过将第一个和最后一个{}替换为[]来更改为关联数组,但应用程序需要它作为映射,而不是关联数组

只是想知道是否有人有类似的问题和任何解决方案


非常感谢。

您使用的
{}
太多了。您应该这样写:

网络映射:{'test_net_1':{'external':true},'test_net_2':{'external':true},'test_net_3':{'external':true}

是的,没错。谢谢。。。