Resource Loading Error in Cocos Creator

I’m trying to load a JSON obj from a file in Cocos Creator using the following code:

resources.load("level1.json", JsonAsset, (err, levelData) => {
     if (err) {
         console.error('Failed to load Level Data:', err);
         return;
     }
     else //Do Something
}

The said file is present in resources folder, but I’m still getting this error when trying to play the game:

Failed to load Level Data: Error: Can not parse this input:{“path”:“level1”,“requestType”:“path”,“bundle”:“”,“preset”:“default”,“priority”:0}

Have tried the following:

  • Play in Editor
  • Play in Browser
  • Filename with Extension (“level1.json”)
  • Filename without Extension (“level1”)

But none of these worked. Anyone has any idea how to fix this issue?

Hi, you should remove the extension part .json from the path of the filename.
Try this

resources.load("level1", JsonAsset, (err, levelData) => {
     if (err) {
         console.error('Failed to load Level Data:', err);
         return;
     }
     else //Do Something
}

@tuan243 thanks for the reply. I had tried that as well, but it didn’t work either. Is there anything else that could be an issue?

That’s weird, I tried

resources.load("test", JsonAsset, (err, data) => {
      if (err != null) {
        console.error(err);
        return;
      }

      console.log("json data", data);
    });

And here is the result. I successfully log it out. I am using Cocos 3.8.6

Thanks a lot for the help Tuan. Found the issue. My resources folder was not in the root (assets) folder of the project, which was causing the issue.

Now it is sorted!

1 Like