I have a Json file and it always goes wrong when I try to read it. I think because it's an array inside another array and I can not read it.
Json:
{
"map": [
["S", "S", "S", "S"],
["S", "S", "C", "S"],
[ "S", "S", "S", "S" ],
["S", "null", "S", "S"]
],
"start": {"X": 3, "Y": 0, "facing": "N"},
"commands": [ "TL","A","C","A","C","TR","A","C"],
"battery": 80
}
Application:
class Program
{
static void Main(string[] args)
{
using (StreamReader r = new StreamReader("../../json1.json"))
{
var json = r.ReadToEnd();
Inicial items = JsonConvert.DeserializeObject<Inicial>(json);
Console.WriteLine(items.battery);
Console.ReadKey();
}
}
public class Inicial
{
public IList<string> map { get; set; }
public string start { get; set; }
public IList<string> commands { get; set; }
public string battery { get; set; }
}
}
The error happens on this line:
Inicial items = JsonConvert.DeserializeObject<Inicial>(json);
Error:
Newtonsoft.Json.JsonReaderException: 'Unexpected character encountered while parsing value: [. Path 'map', line 3, position 5. '