2016-05-22 49 views
0

的二维地图我有一个对象,看起来像这样(数字二维地图):招摇 - 数字

{ 
    10: { 
    12000: 10000000, 
    14000: 23432423, 
    }, 

    20: { 
     35000: 6747665, 
     45000: 54635454 
    } 
} 

,这是什么在招摇的模式定义?

感谢。

回答

0

不幸的是,JSON只允许字符串作为键值名(参见Using number as "index" (JSON)),所提供的例子应该再是这样的:

{ 
    "10": { 
    "12000": 10000000, 
    "14000": 23432423, 
    }, 

    "20": { 
     "35000": 6747665, 
     "45000": 54635454 
    } 
} 

而且在OpenAPI的(FKA扬鞭)规范,可以定义地图,但该键的类型是隐式的,应该是字符串(就像使用JSON一样)。

当描述一个对象是<string, something>的地图时,必须使用additionalProperties来描述something

这里是描述对应于<string, <string, integer>>地图架构的方法有两种:

swagger: '2.0' 

info: 
    version: 1.0.0 
    title: Maps 

paths: {} 

definitions: 
    # a <string, <string, integer>> map using 
    # inline definition of <string, integer> map item 
    TwoDimensionMap: 
    additionalProperties: 
     additionalProperties: 
     type: integer 
     format: int64 

    # a <string, integer> map 
    SimpleMap: 
    additionalProperties: 
     type: integer 
     format: int64 

    # a <string, <string, integer>> map using 
    # $ref definition of <string, integer> map item 
    TwoDimensionMapWithRef: 
    additionalProperties: 
     $ref: '#/definitions/SimpleMap' 

TwoDimensionMap是一个完整的内联定义和TwoDimensionMapWithRef描述完全一样的东西,但使用的引用,另一个定义为内<string, integer>地图。