Mohd Taufeeque

Mohd Taufeeque

  • NA
  • 56
  • 20.9k

How to deserialize or parse the Json object into an array...

May 7 2020 6:25 AM
{
"shapes":[{"id":"A","cursor":"pointer","visual":null,"x":69.25,"y":50},{"name":"Right"},{"name":"Auto"}],"width":10,"height":10},"undoable":true}],
"connections":[{"id":"8Op6PApGWW","selectable":true,"serializable":true,"from":{"shapeId":"A"},"toX":null,"toY":null,"to":{"shapeId":"B"}}]
},
 
This is my json data.
I have to deserialize the data into an array format so i can access the from and to value of connections. 
like var fromid=connections[0].from;
There are more than one shape and connections.
What I have tried is:
string jsonString = diagram.ResponseData.diagramJson;
JArray jsondata = (JArray)JsonConvert.DeserializeObject(jsonString);
 
But It will throw an error.
{"Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'Newtonsoft.Json.Linq.JArray'."}
 
Is anything  wrong while deserializing.

Answers (4)