- Home /
Question by
gdennis · Dec 16, 2014 at 10:05 AM ·
jsonparsingeditorutility
forcing unload a file after error
My game requires a JSON to be loaded in. I use the following code for the user to select his JSON file:
GUILayout.BeginHorizontal ();
if (GUILayout.Button ("Load")) {
string newFilePath = EditorUtility.OpenFilePanel("Select JSON file", Application.streamingAssetsPath, "json");
if (newFilePath.Length != 0) {
JSONLines = "";
filePath = newFilePath;
StreamReader reader = new StreamReader(filePath);
while ((line = reader.ReadLine()) != null)
{
JSONLines += line;
}
JSONParser jp = new JSONParser(JSONLines);
jp.parseJSONData();
}
}
GUILayout.EndHorizontal ();
The JSON parsing is working as intended in the JSONParser class. I also have a static bool in here called 'erorrInJSON'. This is set to true as soon as I notice there is a mistake in the JSON file.
Now this is where my problem lies, how do I properly handle this? I will need somewhere the following code:
if (jp.errorInJSON) {
//show a message to the player that the JSON is not OK
//AND make all the code in this GUILayout.Button ("Load")) restart from 0 ???
}
Thanks in advance to anyone who can help me!
Comment
Your answer
Follow this Question
Related Questions
OpenFilePanel alternative 1 Answer
Paring json Array object 3 Answers
Can't read float array into C# from JSON using Simple JSON 2 Answers
Parsing Facebook graph JSON 1 Answer
Deserialize nested Json data 1 Answer