i am trying to get the "definitions" inside the "senses" array how ever there's an object reference error. I created a class and i can only get the values up to "results" array only e.g(id,language,text and word) but i cant access the "lexicalEntries","entries" and "senses" arrays and there values because of the error.
This is my JSON
"id":"bird",
"metadata":{
"operation":"retrieve",
"provider":"Oxford University Press",
"schema":"RetrieveEntry"
},
"results":[
{
"id":"bird",
"language":"en-gb",
"lexicalEntries":[
{
"entries":[
{
"senses":[
{
"definitions":[
"a warm-blooded egg-laying vertebrate animal distinguished by the possession of feathers, wings, a beak, and typically by being able to fly."
],
"id":"m_en_gbus0097360.006",
"subsenses":[]
},
{
"definitions":[
"a person of a specified kind or character"
],
"id":"m_en_gbus0097360.014"
},
{
"definitions":[
"a young woman or a girlfriend."
],
"id":"m_en_gbus0097360.016"
}
]
}
],
"language":"en-gb",
"lexicalCategory":{
"id":"noun",
"text":"Noun"
},
"text":"bird"
}
],
"type":"headword",
"word":"bird"
}
],
"word":"bird"
}
this is my class
class WordDefinition
{
public RootObject rootObject { get; set; }
public Metadata metadata { get; set; }
public List<Result> results { get; set; }
public List<LexicalEntry> lexicalEntries { get; set; }
public List<Entry> entries { get; set; }
public List<Sens> senses { get; set; }
public List<Subsens> subsenses { get; set; }
public LexicalCategory lexicalCategory { get; set; }
public class Metadata
{
public string operation { get; set; }
public string provider { get; set; }
public string schema { get; set; }
}
public class Subsens
{
public List<string> definitions { get; set; }
public string id { get; set; }
}
public class Sens
{
public List<string> definitions { get; set; }
public string id { get; set; }
public List<Subsens> subsenses { get; set; }
}
public class Entry
{
public List<Sens> senses { get; set; }
}
public class LexicalCategory
{
public string id { get; set; }
public string text { get; set; }
}
public class LexicalEntry
{
public List<Entry> entries { get; set; }
public string language { get; set; }
public LexicalCategory lexicalCategory { get; set; }
public string text { get; set; }
}
public class Result
{
public string id { get; set; }
public string language { get; set; }
public List<LexicalEntry> lexicalEntries { get; set; }
public string type { get; set; }
public string word { get; set; }
}
public class RootObject
{
public string id { get; set; }
public Metadata metadata { get; set; }
public List<Result> results { get; set; }
public string word { get; set; }
}
}
and
var test = JsonConvert.DeserializeObject<WordDefinition>(jsonResponse);
foreach(var testing in test.senses)
{
MessageBox.Show(testing.definitions[0].ToString());
}
I expect the output must be results.definitions[0]. but there's an error:
Object reference not set to an instance of an object error
...in json