'Newtonsoft.Json.Linq.JArray' contains no definition

I am trying to use this code:

string s = "[{status:1,fields:[{name:'n1',value:'v1'}]}]";
dynamic o = JsonConvert.DeserializeObject(s);
var f = o.fields[0].name;  

      

but line 3 gives this error, how did it happen? How do you get this data?

+3


source to share


2 answers


o

- array; you need to get the first element from it:



o[0].fields[0].name

      

+10


source


It should be

 string s = "[{status:1,fields:[{name:'n1',value:'v1'}]}]";
 dynamic o = JsonConvert.DeserializeObject(s);
 var f = o[0].fields[0].name;  

      



Here o is an array object that contains the elements and you want the first one

+3


source







All Articles