1
\$\begingroup\$

The following is my JSON file:

{
    "data" : [
               {
                 "nameString" : "My name is \"Ansar\"",
                 "id" : 1234
               } 
    ]
}

When I try to parse this JSON file using JsonUtility, it is throwing an exception because of the \" character. If I remove the character from the string, it works smoothly.

Exception:

ArgumentException: JSON parse error: Missing a comma or '}' after an object member.
UnityEngine.JsonUtility.FromJson (System.String json, System.Type type) (at /Users/builduser/buildslave/unity/build/Modules/JSONSerialize/Public/JsonUtility.bindings.cs:50)

Why this is happening? Is this a JsonUtility bug? Anyways to fix this?

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Found the solution.

The "nameString" : "My name is \"Ansar\"" should be kept as "nameString" : "My name is \\\"Ansar\\\"". That is Backslash is replaced with \\ .

Resource: https://www.freeformatter.com/json-escape.html

\$\endgroup\$
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .