【问题标题】:Enum values with different types in JSONJSON中不同类型的枚举值
【发布时间】:2014-07-11 11:51:21
【问题描述】:

是否可以在 JSON 模式中将不同类型的枚举值作为键值对传递?

例如:

    "availableproducts" : {
    "enum" : ["Produce 1" : 20.00 , "Product 3" : 30.00 , "Product 7" : 10.00 , "Product 17" : 00.00 ]
   },

或者我需要单独列出数组并将它们组合为键值对吗?

谢谢

已编辑:

架构定义应该是这样的吗? (请注意,我从单独的架构链接到产品。)

"availableproducts" : {
        "description" : "available products for this option ",
        "type" : "array",
            "items" : {
                   "type" : "object",
                    "properties" :{
                           "availableproducts" : {
                               "$ref": "http://mystore.com/schemas#product/properties/name" ,
                               "type" : "string",
                           },

                           "productcost" :{
                                "type" : "number",
                           },
                   }
                },


    },

【问题讨论】:

    标签: arrays json enums


    【解决方案1】:

    你的JOSON错了,ENUM应该是数组,

    那就试试吧;

      "availableproducts" : {
                         "enum" : [{"Produce 1" : 20.00 , "Product 3" : 30.00 , "Product 7" : 10.00 , "Product 17" : 0.00 }]
     }
    

    希望这是你想要的..!!!

    【讨论】:

    • 嘿,谢谢,您将如何在架构文件中预先定义它?它会是一个对象吗?
    • 如果是数组那么转换成json对象就是这样
    • 请参阅上面我编辑的答案。我试图创建一个可以生成以下代码的模式对象。并非所有产品都可在此选项中使用,因此使用枚举解决方案。我的方向正确吗?
    • 只是为了确保清楚。上面的ENUMenumerated type 而不是变量容器。
    猜你喜欢
    • 2021-11-01
    • 2015-10-15
    • 2018-10-18
    • 2019-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多