Fixed a problem that losing the value with loadMember

pull/41/head
Hieromon Ikasamo 6 years ago
parent 02dc8f292d
commit 34a0d45b73
  1. 71
      src/AutoConnectElementJsonImpl.h

@ -60,7 +60,8 @@ void AutoConnectElementJson::_serialize(JsonObject& json) {
*/ */
void AutoConnectElementJson::_setMember(const JsonObject& json) { void AutoConnectElementJson::_setMember(const JsonObject& json) {
name = json.get<String>(F(AUTOCONNECT_JSON_KEY_NAME)); name = json.get<String>(F(AUTOCONNECT_JSON_KEY_NAME));
value = json.get<String>(F(AUTOCONNECT_JSON_KEY_VALUE)); if (json.containsKey(F(AUTOCONNECT_JSON_KEY_VALUE)))
value = json.get<String>(F(AUTOCONNECT_JSON_KEY_VALUE));
} }
/** /**
@ -81,7 +82,8 @@ bool AutoConnectButtonJson::loadMember(const JsonObject& json) {
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE));
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACBUTTON))) { if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACBUTTON))) {
_setMember(json); _setMember(json);
action = json.get<String>(F(AUTOCONNECT_JSON_KEY_ACTION)); if (json.containsKey(F(AUTOCONNECT_JSON_KEY_ACTION)))
action = json.get<String>(F(AUTOCONNECT_JSON_KEY_ACTION));
return true; return true;
} }
return false; return false;
@ -116,8 +118,10 @@ bool AutoConnectCheckboxJson::loadMember(const JsonObject& json) {
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE));
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACCHECKBOX))) { if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACCHECKBOX))) {
_setMember(json); _setMember(json);
label = json.get<String>(F(AUTOCONNECT_JSON_KEY_LABEL)); if (json.containsKey(F(AUTOCONNECT_JSON_KEY_LABEL)))
checked = json.get<bool>(F(AUTOCONNECT_JSON_KEY_CHECKED)); label = json.get<String>(F(AUTOCONNECT_JSON_KEY_LABEL));
if (json.containsKey(F(AUTOCONNECT_JSON_KEY_CHECKED)))
checked = json.get<bool>(F(AUTOCONNECT_JSON_KEY_CHECKED));
return true; return true;
} }
return false; return false;
@ -154,9 +158,12 @@ bool AutoConnectInputJson::loadMember(const JsonObject& json) {
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE));
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACINPUT))) { if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACINPUT))) {
_setMember(json); _setMember(json);
label = json.get<String>(F(AUTOCONNECT_JSON_KEY_LABEL)); if (json.containsKey(F(AUTOCONNECT_JSON_KEY_LABEL)))
pattern = json.get<String>(F(AUTOCONNECT_JSON_KEY_PATTERN)); label = json.get<String>(F(AUTOCONNECT_JSON_KEY_LABEL));
placeholder = json.get<String>(F(AUTOCONNECT_JSON_KEY_PLACEHOLDER)); if (json.containsKey(F(AUTOCONNECT_JSON_KEY_PATTERN)))
pattern = json.get<String>(F(AUTOCONNECT_JSON_KEY_PATTERN));
if (json.containsKey(F(AUTOCONNECT_JSON_KEY_PLACEHOLDER)))
placeholder = json.get<String>(F(AUTOCONNECT_JSON_KEY_PLACEHOLDER));
return true; return true;
} }
return false; return false;
@ -193,17 +200,23 @@ bool AutoConnectRadioJson::loadMember(const JsonObject& json) {
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE));
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACRADIO))) { if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACRADIO))) {
_setMember(json); _setMember(json);
label = json.get<String>(F(AUTOCONNECT_JSON_KEY_LABEL)); if (json.containsKey(F(AUTOCONNECT_JSON_KEY_LABEL)))
checked = static_cast<uint8_t>(json.get<int>(F(AUTOCONNECT_JSON_KEY_CHECKED))); label = json.get<String>(F(AUTOCONNECT_JSON_KEY_LABEL));
String arrange = json.get<String>(F(AUTOCONNECT_JSON_KEY_ARRANGE)); if (json.containsKey(F(AUTOCONNECT_JSON_KEY_CHECKED)))
if (arrange.equalsIgnoreCase(F(AUTOCONNECT_JSON_KEY_VERTICAL))) checked = static_cast<uint8_t>(json.get<int>(F(AUTOCONNECT_JSON_KEY_CHECKED)));
order = AC_Vertical; if (json.containsKey(F(AUTOCONNECT_JSON_KEY_ARRANGE))) {
else if (arrange.equalsIgnoreCase(F(AUTOCONNECT_JSON_KEY_HORIZONTAL))) String arrange = json.get<String>(F(AUTOCONNECT_JSON_KEY_ARRANGE));
order = AC_Horizontal; if (arrange.equalsIgnoreCase(F(AUTOCONNECT_JSON_KEY_VERTICAL)))
empty(); order = AC_Vertical;
JsonArray& optionArray = json[AUTOCONNECT_JSON_KEY_VALUE]; else if (arrange.equalsIgnoreCase(F(AUTOCONNECT_JSON_KEY_HORIZONTAL)))
for (auto value : optionArray) order = AC_Horizontal;
add(value.as<String>()); }
if (json.containsKey(F(AUTOCONNECT_JSON_KEY_VALUE))) {
empty();
JsonArray& optionArray = json[AUTOCONNECT_JSON_KEY_VALUE];
for (auto value : optionArray)
add(value.as<String>());
}
return true; return true;
} }
return false; return false;
@ -249,12 +262,16 @@ bool AutoConnectSelectJson::loadMember(const JsonObject& json) {
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE));
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACSELECT))) { if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACSELECT))) {
_setMember(json); _setMember(json);
label = json.get<String>(F(AUTOCONNECT_JSON_KEY_LABEL)); if (json.containsKey(F(AUTOCONNECT_JSON_KEY_LABEL))) {
empty(); label = json.get<String>(F(AUTOCONNECT_JSON_KEY_LABEL));
JsonArray& optionArray = json[AUTOCONNECT_JSON_KEY_OPTION]; }
for (auto value : optionArray) if (json.containsKey(F(AUTOCONNECT_JSON_KEY_OPTION))) {
add(value.as<String>()); empty();
return true; JsonArray& optionArray = json[AUTOCONNECT_JSON_KEY_OPTION];
for (auto value : optionArray)
add(value.as<String>());
return true;
}
} }
return false; return false;
} }
@ -290,7 +307,8 @@ bool AutoConnectSubmitJson::loadMember(const JsonObject& json) {
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE));
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACSUBMIT))) { if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACSUBMIT))) {
_setMember(json); _setMember(json);
uri = json.get<String>(F(AUTOCONNECT_JSON_KEY_URI)); if (json.containsKey(F(AUTOCONNECT_JSON_KEY_URI)))
uri = json.get<String>(F(AUTOCONNECT_JSON_KEY_URI));
return true; return true;
} }
return false; return false;
@ -325,7 +343,8 @@ bool AutoConnectTextJson::loadMember(const JsonObject& json) {
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE));
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACTEXT))) { if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACTEXT))) {
_setMember(json); _setMember(json);
style = json.get<String>(F(AUTOCONNECT_JSON_KEY_STYLE)); if (json.containsKey(F(AUTOCONNECT_JSON_KEY_STYLE)))
style = json.get<String>(F(AUTOCONNECT_JSON_KEY_STYLE));
return true; return true;
} }
return false; return false;

Loading…
Cancel
Save