Click here to Skip to main content
15,887,350 members
Home / Discussions / C#
   

C#

 
AnswerRe: Having Trouble With this code Pin
Ahmad Bukhari21-Sep-16 20:01
Ahmad Bukhari21-Sep-16 20:01 
AnswerRe: Having Trouble With this code Pin
RizingPhoenix21-Sep-16 20:57
RizingPhoenix21-Sep-16 20:57 
SuggestionRe: Having Trouble With this code Pin
Richard Deeming22-Sep-16 1:54
mveRichard Deeming22-Sep-16 1:54 
GeneralRe: Having Trouble With this code Pin
Kelly Herald2-Nov-16 9:22
Kelly Herald2-Nov-16 9:22 
QuestionFileSystemWatcher in c # Pin
Luis_Saenz21-Sep-16 4:46
Luis_Saenz21-Sep-16 4:46 
SuggestionRe: FileSystemWatcher in c # Pin
ZurdoDev21-Sep-16 5:05
professionalZurdoDev21-Sep-16 5:05 
AnswerRe: FileSystemWatcher in c # Pin
Maciej Los21-Sep-16 5:08
mveMaciej Los21-Sep-16 5:08 
QuestionJSON.Net - Error when I get value from a JToken that could be either a JValue or JArray Pin
inquisitive_121-Sep-16 3:48
inquisitive_121-Sep-16 3:48 
I'm trying to select all users with a roleId of 4. How can I do that? Here's my JSON string:
JavaScript
{
		"?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:
C#
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.<br />
	Parameter name: value


In the end, my results should be: Joe Schmoe & Steve Jobs, only.

What am I doing wrong?

modified 21-Sep-16 12:13pm.

AnswerRe: JSON.Net - Error when I get value from a JToken that could be either a JValue or JArray Pin
onelopez21-Sep-16 4:59
onelopez21-Sep-16 4:59 
GeneralRe: JSON.Net - Error when I get value from a JToken that could be either a JValue or JArray Pin
inquisitive_121-Sep-16 6:11
inquisitive_121-Sep-16 6:11 
AnswerRe: JSON.Net - Error when I get value from a JToken that could be either a JValue or JArray Pin
Nathan Minier21-Sep-16 5:09
professionalNathan Minier21-Sep-16 5:09 
GeneralRe: JSON.Net - Error when I get value from a JToken that could be either a JValue or JArray Pin
inquisitive_121-Sep-16 5:57
inquisitive_121-Sep-16 5:57 
QuestionControl is very similar ComboBox to what's it the name ? Pin
Member 245846720-Sep-16 16:18
Member 245846720-Sep-16 16:18 
AnswerRe: Control is very similar ComboBox to what's it the name ? Pin
BillWoodruff21-Sep-16 3:05
professionalBillWoodruff21-Sep-16 3:05 
QuestionRe: Control is very similar ComboBox to what's it the name ? Pin
ZurdoDev21-Sep-16 3:27
professionalZurdoDev21-Sep-16 3:27 
QuestionFTP Multiple Files With Progress Pin
Kevin Marois20-Sep-16 9:40
professionalKevin Marois20-Sep-16 9:40 
AnswerRe: FTP Multiple Files With Progress Pin
Bernhard Hiller20-Sep-16 20:47
Bernhard Hiller20-Sep-16 20:47 
GeneralRe: FTP Multiple Files With Progress Pin
Kevin Marois21-Sep-16 9:13
professionalKevin Marois21-Sep-16 9:13 
GeneralRe: FTP Multiple Files With Progress Pin
Bernhard Hiller21-Sep-16 20:54
Bernhard Hiller21-Sep-16 20:54 
GeneralRe: FTP Multiple Files With Progress Pin
Kevin Marois22-Sep-16 6:07
professionalKevin Marois22-Sep-16 6:07 
AnswerRe: FTP Multiple Files With Progress Pin
Peter_in_278022-Sep-16 15:07
professionalPeter_in_278022-Sep-16 15:07 
SuggestionRe: FTP Multiple Files With Progress Pin
Richard Deeming21-Sep-16 2:51
mveRichard Deeming21-Sep-16 2:51 
GeneralRe: FTP Multiple Files With Progress Pin
Kevin Marois21-Sep-16 9:19
professionalKevin Marois21-Sep-16 9:19 
QuestionIndexOutOfRange Exception When Using Multi Dimensional Array Pin
MadDashCoder20-Sep-16 6:07
MadDashCoder20-Sep-16 6:07 
AnswerRe: IndexOutOfRange Exception When Using Multi Dimensional Array Pin
OriginalGriff20-Sep-16 6:18
mveOriginalGriff20-Sep-16 6:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.