Skip to content

Get value by key from JObject: retarget net10.0, make Program.cs run the four approaches - #2225

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/80702-csharp-get-value-by-key-from-jobject
Open

vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/80702-csharp-get-value-by-key-from-jobject

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Sample for the article "JObject in C#: How to Get Value by Key" (json-csharp/GetValueByKeyFromJObject). This PR touches only that folder.

Changes:

  • Both projects retargeted from net7.0 to net10.0.
  • Program.cs now constructs JObjectManipulation once and calls the four methods in the article's order. It used to print "Application Started" and exit, so the console output the article shows could only be seen by running the tests.
  • GetValuesUsingValueMethod reads year with Value("year") instead of Value("year"), matching the int the other three approaches read.
  • TestData.cs uses a plain raw string literal (""") instead of $$""". The JSON has no interpolation in it.

Package versions, re-queried on NuGet on 2026-09-23 (newest stable of each):

  • Newtonsoft.Json 13.0.2 to 13.0.4
  • Microsoft.NET.Test.Sdk 17.3.2 to 18.10.1 (the batch policy named 18.10.0; the re-query found 18.10.1 and that is what this PR uses)
  • xunit 2.4.2 to 2.9.3
  • xunit.runner.visualstudio 2.4.5 to 4.0.0
  • coverlet.collector 3.1.2 to 10.0.1

Verified locally on SDK 10.0.302, runtime 10.0.10:

  • dotnet build -c Release: 0 warnings, 0 errors
  • dotnet test -c Release: Failed 0, Passed 4, Total 4
  • dotnet list package --vulnerable --include-transitive: no vulnerable packages in either project
  • dotnet run prints the index, Value() and SelectToken() line three times and the four TryGetValue() lines, as the article shows.

…the four approaches

- Both projects move from net7.0 to net10.0.
- Newtonsoft.Json 13.0.2 to 13.0.4; Microsoft.NET.Test.Sdk 17.3.2 to 18.10.1;
  xunit 2.4.2 to 2.9.3; xunit.runner.visualstudio 2.4.5 to 4.0.0;
  coverlet.collector 3.1.2 to 10.0.1.
- Program.cs constructs JObjectManipulation once and calls the four methods in
  the article's order, so running the sample prints the output the article shows.
- GetValuesUsingValueMethod reads year with Value<int>, matching the int cast
  the other approaches use.
- TestData.cs uses a plain raw string literal; the JSON has no interpolation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant