2016-11-22 74 views
4

我有一个JSON:如何为Map <String,Integer>定义JSON模式?

{ 
"itemType": {"food":22,"electrical":2}, 
"itemCount":{"NA":211} 
} 

这里ITEMTYPE和ITEMCOUNT将是常见的,但不是在他们里面(食品,NA,电),这将在不断变化,但会在格式值:地图

如何为这样的通用结构定义Json Schema?

我想:

"itemCount":{ 
     "type": "object" 
    "additionalProperties": {"string", "integer"} 

    } 
+0

通过定义JSON shcema,你问怎么写表示JSON一类? –

+0

@ J.West没有JSON形式的Schema – Newbie

+0

这是你想参考的[example](http://json-schema.org/example1.html)吗? –

回答

7

您可以:

{ 
    "type": "object", 
    "properties": { 
    "itemType": {"$ref": "#/definitions/mapInt"}, 
    "itemCount": {"$ref": "#/definitions/mapInt"} 
    }, 
    "definitions": { 
    "mapInt": { 
     "type": "object", 
     "additionalProperties": {"type": "integer"} 
    } 
    } 
} 
+0

我们如何在这里指定哪两个应该被视为“关键”? – sachinjain024

相关问题