C# Deserialize JSON string into object using Newtonsoft.Json -


i trying convert json string object using newtonsoft.json, having problems following conversion. wonder if 1 can explain this. thanks.

addfaceresponse ir = jsonconvert.deserializeobject<addfaceresponse>(responsecontentstr); 

this json string responsecontentstr

[{     "faceid": "1fe48282-a3b0-47d1-8fa8-67c4fac3d984",     "facerectangle": {         "top": 80,         "left": 50,         "width": 147,         "height": 147     } }] 

this model object.

public class addfaceresponse     {         public class face         {             public class facerectangle             {                 public int top, left, width, height;                 public facerectangle(int t, int l, int w, int h)                 {                     top = t;                     left = l;                     width = w;                     height = h;                 }             }             public string faceid;             public facerectangle facerectangle;             public face(string id, facerectangle fac)             {                 faceid = id;                 facerectangle = fac;             }         }          face[] faces;         public addfaceresponse(face[] f)         {             faces = f;         }     } 

this error getting visual studio.

newtonsoft.json.jsonserializationexception: cannot deserialize current json array (e.g. [1,2,3]) type 'app2.addfaceresponse' because type requires json object (e.g. {"name":"value"}) deserialize correctly

you deserializing array object. work with;

var faces = jsonconvert.deserializeobject<face[]>(responsecontentstr); 

or wrap json string pair of accolades { }, , add property;

{"faces":[.. json string ..]} 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -