Improper JSON formatting when decode JSON in Unity3D

Hi people,

I am using the JSON parser from the Unify Community Wiki as below:

I follow the instruction in setting up the JSON parser and this is how i call the JSON parser as below:

However, i keep getting the error as below:

improper JSON formatting:file://D:/Project Files/Unity Project (Jukebox_r10)/Assets/Resources/sample.json
JSONObject:.ctor(String) (at Assets/Customized Script/JSONObject.cs:126)
Startup:Update() (at Assets/Customized Script/Startup.cs:20)

Can any kind soul enlight me on what is really going wrong in my script?

Thanks in advance. :slight_smile:

As Jace guesses in the comments, JSONObject doesn’t take an encoded string but a filename. With what you have it tries to decode the filename as JSON, which of course fails.

So you have to load the JSON string yourself:

string encodedString = LoadStringFromFile(); // your function...
JSONObject j = new JSONObject(encodedString);