4
I have a Json file and it always gives error when I try to read it. I believe because it is an array within another array and I cannot read.
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
}
Applying:
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.'
Thank you very much! Clarified me and worked perfectly!
– israel3D