I have a Json:
[
[
[
{
"origin": [
-15.2941064136735,
-0.43948581648487,
4.83674058264479
],
"dimensions": [
10.4597624323399,
11.6903227184975,
9.67348116528958
],
"primitive": "block"
}
],
[
{
"origin": [
-15.2941064136735,
-0.43948581648487,
4.83674058264479
],
"dimensions": [
10.4597624323399,
11.6903227184975,
9.67348116528958
],
"primitive": "block"
}
],
[
{
"origin": [
-15.2941064136735,
-0.43948581648487,
4.83674058264479
],
"dimensions": [
10.4597624323399,
11.6903227184975,
9.67348116528958
],
"primitive": "block"
}
]
]
]
And model for this Json:
public class BoxConverter
{
[JsonProperty("origin")]
public List<double> Origin { get; set; }
[JsonProperty("dimensions")]
public List<double> Dimensions { get; set; }
[JsonProperty("primitive")]
public string Primitive { get; set; }
}
And i try get list of objects from json which in file.
string strLocal = File.ReadAllText("2.txt");
var convertLocal = JsonConvert.DeserializeObject<List<BoxConverter>>(strLocal);
But I have a exception :
Cannot deserialize the current JSON array (e.g. [1,2,3]) into type because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path '[0]', line 1, position 2.
What I'm doing wrong?
UPDATE
With this JSON work perfectly :
[{"attributes":{"materialProperties":{"color":"red","wireframe":false}},"dimensions":[10.4597624323399,11.6903227184975,9.67348116528958],"origin":[-15.2941064136735,-0.43948581648487,4.83674058264479],"primitive":"block"}]