jsonUtility help

jsonUtility help  



I'm able to save as a binary input and pull it back into a game but having problems trying to understand JsonUtility to save as a json file with a set path and name. Anyone had any success with this?  

public void SaveAsJSON()

string json = JsonUtility.ToJson(this); * I know "this" is wrong
Save save = JsonUtility.FromJson<Save>(savePath + json);  * savePath is a global variable

Debug.Log("Saving as JSON: " + json);  * message is not displaying because of the string json


I assume you aren't getting to the Debug.Log because it's throwing an exception or some other type of error. Are you seeing anything in the console?

According to the Docs for "FromJson", you are just supposed to Feed it a JSON string.  So the SavePath would be wrong.. Basically what you are doing is taking a json, say: { status: false, message:  "Test"} to C:\temp\{status: false, message: "Test"}, which obviously isn't valid JSON. 


Are you trying to save the JSON out to a file?

Well after years of trying to deal with io.system I was trying to prevent not being able to see where the json data is going.

1 Answer

To anyone that may look at this question later, we talked privately and found that it was a simple misunderstand of what the class is doing.  

Using System.IO.File to read and write the JSON and JsonUtil to serialize and de-serialize




Scroll to Top

Please Login or Register