I was trying to load a .json file and read it using “JsonReaderWriterFactory”.
My code is the following:
string path = Server.MapPath(Url.Content("~/")) + "JsonData/file.json";
byte[] buffer = System.IO.File.ReadAllBytes(path);
System.Xml.XmlReader reader = System.Runtime.Serialization.Json.JsonReaderWriterFactory.CreateJsonReader(buffer, System.Xml.XmlDictionaryReaderQuotas.Max);
System.Xml.Linq.XElement root = System.Xml.Linq.XElement.Load(reader);
But when I call “System.Xml.Linq.XElement.Load(reader)” I get an exception “unexpected character ‘ï’“.
What’s wrong?
Should I specify a particular encode?
Thank you.
Data I am trying to read should be an array of objects composed in this way:
[
{
id: "ITEM_ID",
label: "Item Label",
url: "http://www.address.com",
parameters: [
"PARAM_1",
"PARAM_2"
],
filters: {
logic: "or",
filters: [
{ field: "fieldA", operator: "eq", value: 100 },
{
logic: "and",
filters: [
{ field: "fieldA", operator: "lt", value: 100 },
{ field: "fieldB", operator: "eq", value: true }
]
}
]
}
},
{...},
{...}
]
first I would suggest you to validate your Json Data at http://jsonlint.com/
It seems that your Json data is not well formatted.
The error is coming because you haven’t wrapped your keys with
" "marks.So it has to be like these.