From 7ba12439fa7f63c41e01902846c15c19c642cad4 Mon Sep 17 00:00:00 2001 From: Mike Melancon Date: Mon, 9 Oct 2023 16:11:27 -0500 Subject: [PATCH] Fixed bug in JSONEncoder when trying to create a member whose value is an object --- FluidNC/src/WebUI/JSONEncoder.cpp | 10 ++++++++++ FluidNC/src/WebUI/JSONEncoder.h | 10 ++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/FluidNC/src/WebUI/JSONEncoder.cpp b/FluidNC/src/WebUI/JSONEncoder.cpp index 4c6cc6fa9..68db060cc 100644 --- a/FluidNC/src/WebUI/JSONEncoder.cpp +++ b/FluidNC/src/WebUI/JSONEncoder.cpp @@ -149,6 +149,16 @@ namespace WebUI { add(']'); } + // Begins the creation of a member whose value is an object. + // Call end_object() to close the member + void JSONencoder::begin_member_object(const char* tag) { + comma_line(); + quoted(tag); + add(':'); + add('{'); + inc_level(); + } + // Starts an object with {. // If you need a named object you must call begin_member() first. void JSONencoder::begin_object() { diff --git a/FluidNC/src/WebUI/JSONEncoder.h b/FluidNC/src/WebUI/JSONEncoder.h index 7d8298fc7..e5444ff74 100644 --- a/FluidNC/src/WebUI/JSONEncoder.h +++ b/FluidNC/src/WebUI/JSONEncoder.h @@ -22,6 +22,9 @@ namespace WebUI { void indent(); void line(); + // begin_member() starts the creation of a member. + void begin_member(const char* tag); + std::string linebuf; std::string* _str = nullptr; @@ -58,10 +61,9 @@ namespace WebUI { // end_object() closes the object with } void end_object(); - // begin_member() starts the creation of a member. - // The only case where you need to use it directly - // is when you want a member whose value is an object. - void begin_member(const char* tag); + // Begins the creation of a member whose value is an object. + // Call end_object() to close the member + void begin_member_object(const char* tag); // The begin_webui() methods are specific to Esp3D_WebUI // WebUI sends JSON objects to the UI to generate configuration