Browse Source

fix parsing error for escaped characters in json strings

Kolja Strohm 8 months ago
parent
commit
5304978485
1 changed files with 6 additions and 3 deletions
  1. 6 3
      JSON.cpp

+ 6 - 3
JSON.cpp

@@ -122,8 +122,8 @@ JSONString::JSONString(Text string)
     : JSONValue(JSONType::STRING)
 {
     this->string = string;
-    string.ersetzen("\\\"", "\"");
-    string.ersetzen("\\n", "\n");
+    this->string.ersetzen("\\\"", "\"");
+    this->string.ersetzen("\\n", "\n");
 }
 
 Text JSONString::getString() const
@@ -141,7 +141,10 @@ Text JSONString::toString() const
 
 JSONValue* JSONString::clone() const
 {
-    return new JSONString(string);
+    Text esc = string;
+    esc.ersetzen("\"", "\\\"");
+    esc.ersetzen("\n", "\\n");
+    return new JSONString(esc);
 }
 
 #pragma endregion Content