我们必须返回一个包含用户配置数据的对象。某些字段具有指示此字段是否已锁定的属性,是否为必填字段等。
¿以JSON的形式返回此对象的正确结构是什么?我们考虑了
选项1:
{
"id": "123456",
"config":{
"field1" : "some-value",
"field2" : true,
"field3" : 23.1,
"locked-fields" : ["field1", "field3"],
"mandatory-fields" : ["field2", "field3"]
},
"data" : {
"data-section-1":{
"data-field1" : "some-value",
"data-field2" : "some-value",
"locked-fields" : ["data-field1"],
"mandatory-fields" : ["data-field2"]
},
"data-section-2":{
"data-field3" : "some-value",
"data-field4" : "some-value",
"locked-fields" : ["data-field3", "data-field4"]
}
}
}
选项2:
{
"id": "123456",
"config":{
"field1" : { "value" : "some-value", "locked" : true, "mandatory" : false},
"field2" : { "value" : true, "locked" : false, "mandatory" : true},
"field3" : { "value" : 23.1, "locked" : true, "mandatory" : true}
},
"data" : {
"data-section-1":{
"data-field1" : { "value" : "some-value", "locked" : true, "mandatory" : false},
"data-field2" : { "value" : "some-value", "locked" : false, "mandatory" : true}
},
"data-section-2":{
"data-field3" : { "value" : "some-value", "locked" : true, "mandatory" : false},
"data-field4" : { "value" : "some-value", "locked" : true, "mandatory" : false}
}
}
}
哪个最正确?另一个sugerence?
感谢。
答案 0 :(得分:1)
我会选择选项2。
"锁定"或者"强制性的"对我来说是某种对象(在这种情况下Field
)具有的属性。第二个Json代表"锁定"和"强制性"作为Field
对象的这些属性,所以它看起来更好。