Skip to content

Commit

Permalink
new escape options added to Json/JsonUtility Escape method
Browse files Browse the repository at this point in the history
  • Loading branch information
vahid committed Nov 27, 2023
1 parent dabca76 commit d18efad
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions 01-Core/Jinget.Core/Utilities/Json/JsonUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,27 @@ public static bool IsValid(string input)
public static string Unescape(string json, bool removeNewLine = true)
{
json = json
.Replace(@"\\\""", "\"")
.Replace(@"\""", "\"")
.Replace("\"[{\"", "[{\"")
.Replace("\"}]\"", "\"}]")
.Replace("\"{", "{")
.Replace("}\"", "}")
.Replace("\"[", "[")
.Replace("]\"", "]");

.Replace(@"\\\""", "\"") // ==? \\"" ==> "
.Replace(@"\""", "\"") //==> "" ==> "
.Replace("\"[{\"", "[{\"")//==> "[{" ==> [{"
.Replace("\"}]\"", "\"}]") //==> "}]" ==> "}]
.Replace("\"{", "{")// =="{ ==> {
.Replace("}\"", "}")//==> }" ==> }
.Replace("\"[", "[")//==> "[ ==> [
.Replace("]\"", "]") //==> ]" ==> ]

//order of the follwoings are matter!
.Replace(":\"\",", ":\"---\",")//==> :"", ==> :"---",
.Replace(":\"\"}", ":\"---\"}")//==> :""} ==> :"---"}
.Replace(":\"\"", ":\"")//==> :"" ==> :"
.Replace("\"\",", "\",");//==> "" ==> "

if (removeNewLine)
json = json.Replace(System.Environment.NewLine, "");
{
json = json
.Replace(System.Environment.NewLine, "")
.Replace(@"\r\n", "");
}

return json;
}
Expand Down

0 comments on commit d18efad

Please sign in to comment.