I'm getting the following error: NullReferenceException: Object reference not set to an instance of an object.
inquisitive_1
Posts
-
JSON.Net - Error when I get value from a JToken that could be either a JValue or JArray -
JSON.Net - Error when I get value from a JToken that could be either a JValue or JArraySorry. I don't have any control over that. Yes, it makes more sense if it was always an array, but that's what I get from the web service feed.
-
JSON.Net - Error when I get value from a JToken that could be either a JValue or JArrayI'm trying to select all users with a roleId of 4. How can I do that? Here's my JSON string:
{
"?xml" : {
"@version" : "1.0",
"@encoding" : "UTF-8"
},
"DataFeed" : {
"@FeedName" : "AdminData",
"People" : [{
"id" : "63",
"active" : "1",
"firstName" : "Joe",
"lastName" : "Schmoe",
"roleIds" : {
"int" : "4"
}
} , {
"id" : "65",
"active" : "1",
"firstName" : "Steve",
"lastName" : "Jobs",
"roleIds" : {
"int" : ["4", "16", "25", "20", "21", "22", "17", "23", "18"]
}
} , {
"id" : "66",
"active" : "1",
"firstName" : "Bill",
"lastName" : "Gates",
"roleIds" : {
"int" : ["3", "16", "25", "20"]
}
}
]
}
}Here's the query that I'm using:
JObject jsonFeed = JObject.Parse(jsonText);
from people in jsonFeed.SelectTokens("DataFeed.People").SelectMany(i => i.ObjectsOrSelf()) where (int)people\["active"\] == 1 && (int)people\["roleIds.int"\] == 4 // <-- this causes the error select new PeopleClass { Id = (int)people\["id"\], ResAnFName = (string)people\["firstName"\], ResAnLName = (string)people\["lastName"\] }
I'm getting the following error on
(int)people["roleIds.int"] == 4
:ArgumentNullException: Value cannot be null. Parameter name: value
In the end, my results should be:Joe Schmoe
&Steve Jobs
, only. What am I doing wrong?