From fb28f86ae93d59a47cad2ff8f3f5b3c97312ec0c Mon Sep 17 00:00:00 2001 From: Charl Wentzel Date: Tue, 16 Jul 2019 16:43:55 +0200 Subject: [PATCH] Important Update: - JSONparse: - Allow base entry to be Array or Object - Do not enforce escaping of '/' -> '\/' - Bug fix: properly encode string values in arrays --- JSONparseCore.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/JSONparseCore.cpp b/JSONparseCore.cpp index cbf39c4..ef35ed0 100644 --- a/JSONparseCore.cpp +++ b/JSONparseCore.cpp @@ -352,11 +352,11 @@ bool CJSONparse::ReadFromBuffer( const char * BasePath ) // Parse Root Object SkipWhiteSpace(); - if (!ParseObject( BaseMember )) { + if (!ParseObject( BaseMember ) && !Error && !ParseArray( BaseMember )) { if (!Error) { Error = true; CharNo += BufPos-Mark; - sprintf( ErrorText, "First entry in file must be an Object on line %d:%d", LineNo, CharNo ); + sprintf( ErrorText, "First entry in file must be an Object or Array on line %d:%d", LineNo, CharNo ); } FreeBuffer(); return false; @@ -475,7 +475,7 @@ bool CJSONparse::ParseString( char ** Value, int &Len ) while (true) { // Check for special characters - if ((EndMark = strpbrk( BufPos, "\"/\\\n\t\b\f\n\r" ))) { + if ((EndMark = strpbrk( BufPos, "\"\\\n\t\b\f\n\r" ))) { /*"\"/\\\n\t\b\f\n\r" (forward slash included)*/ BufPos = EndMark; } else if (RefillBuffer) { FillBuffer(); @@ -816,7 +816,7 @@ bool CJSONparse::PrintString( char * String, int Len ) { // Scan for special chars Mark = BufPos; - while ((*BufPos >= 32) && (*BufPos <= 126) && (*BufPos != '\\') && (*BufPos != '/') && (*BufPos != '"')) + while ((*BufPos >= 32) && (*BufPos <= 126) && (*BufPos != '\\') && /*(*BufPos != '/') &&*/ (*BufPos != '"')) BufPos++; // Print Portion @@ -1029,9 +1029,7 @@ bool CJSONparse::PrintArray( CDataMember * Array, const int Indent ) break; case jtString : - if ((Print( this, "\"", 1 ) < 0) || - (Print( this, Member->Value, Member->Len ) < 0) || - (Print( this, "\"", 1 ) < 0)) + if (!PrintString( Member->Value, Member->Len )) return false; break;