I'm trying to load a class using JsonUtility to populate a few strings. I navigate to the file using Unity Simple File Browser and load it using the following coroutine:

IEnumerator ShowLoad()
{

if (FileBrowser.Success)
{
Debug.Log("File Browsed: " + FileBrowser.Result[0]);

UnityWebRequest url = new UnityWebRequest("file:///" + FileBrowser.Result[0]);

yield return url;

Campaign c = JsonUtility.FromJson<Campaign>(json);
CampaignName = c.CampaignName;
saveFolder = c.saveFolder;
savePath = c.savePath;
persistentFolder = c.persistentFolder;
persistentPath = c.persistentPath;
}
}


But every time I try to run the code I get the following error:

FileNotFoundException: Could not find file "C:\Users\arily\Documents\GitKraken\DND-Astra\Astra\UnityEngine.Networking.UnityWebRequest"
System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) (at <7b935204f5ff4bcab44b3b0ebca330bf>:0)
System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.IO.FileOptions options) (at <7b935204f5ff4bcab44b3b0ebca330bf>:0)
(wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,int,System.IO.FileOptions)
System.IO.StreamReader..ctor (System.String path, System.Text.Encoding encoding, System.Boolean detectEncodingFromByteOrderMarks, System.Int32 bufferSize) (at <7b935204f5ff4bcab44b3b0ebca330bf>:0)
System.IO.StreamReader..ctor (System.String path, System.Boolean detectEncodingFromByteOrderMarks) (at <7b935204f5ff4bcab44b3b0ebca330bf>:0)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <ab7de6937a4448b0a6ccd59e9820599a>:0)


I have tried the same method using WWW to load an image and it worked, but when loading a JSON using WWW I get the same error referring to UnityEngine.WWW instead. I haven't been able to find anything online about it, so I'm posting here. Any insight or tips would be much appreciated, thank you!

"C:\Users\arily\Documents\GitKraken\DND-Astra\Astra\UnityEngine.Networking.UnityWebRequest"

Surely that should be something more like,

"C:\Users\arily\Documents\GitKraken\DND-Astra\Astra\myfile.json"

I think you've got this part wrong:

FileBrowser.Result[0]

Should probably be something like FileBrowser.Result[0].fileName as its currently converting an object to a string representation.

• Rather than that, Arilyn is also making a new UnityWebRequest of a local file. That seems kinda wrong too. According to the github, FileBrowserHelpers.ReadBytesFromFile( FileBrowser.Result[0] ) returns a byte[] May 9 at 18:09
• That's what I thought - was going to suggest running a webserver - but the solution should fit the problem, rather than vice-versa. May 9 at 18:10
• Hi, thanks for your comments. The Debug.Log statement outputs the correct path. The result isn't the issue, I don't think, since using the .ToString method didn't change anything. Line 90 is referred to in the error which ends up being StreamReader reader = new StreamReader(url.ToString()); May 9 at 22:21
• You dont want to use UnityWebRequest if you want to load a local file May 9 at 22:29
• @Arilyn want to post your solution as an Answer below? May 10 at 0:20