Quantcast
Channel: Questions in topic: "parser"
Viewing all articles
Browse latest Browse all 108

"ArgumentException: JSON parse error: Invalid value." thrown on valid JSON

$
0
0
Hello -- I'm trying to parse a simple JSON file with a list but the following error is being thrown: ArgumentException: JSON parse error: Invalid value. I understand this generally means that the JSON is malformed but I don't think this is the case here. Because the error points to a line error in the parser itself I don't even know where Unity thinks the invalid value is. The this is the JSON (I'm pretty sure the JSON itself is valid, I've run it through validators, and had an extra pair of eyes on it.): { "fragments": [ {"text": "hello world"}, {"text": "goodbye cruel world"} ] } Here is the unwrapper: using System.Collections; using System.Collections.Generic; using UnityEngine; using System; [Serializable] public class SimplifiedConversationData{ public List fragments; } [Serializable] public class Fragment { public string text; } And finally the monobehaviour that uses this JSON (the StreamReader prints the correct JSON): using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO; public class Test : MonoBehaviour { private string conversationPath = "SimplifiedConversation.json"; void Awake(){ LoadGameData(); } private void LoadGameData(){ string filePath = Path.Combine(Application.streamingAssetsPath, conversationPath); if(File.Exists(filePath)){ StreamReader reader = new StreamReader(filePath); Debug.Log(reader.ReadToEnd()); reader.Close(); var parsed = JsonUtility.FromJson(filePath); } } } This is otherwise a completely fresh project. Thank you very much for taking the time to look at this.

Viewing all articles
Browse latest Browse all 108

Trending Articles