Some parts of json.net in .net core won't work

148 Views Asked by At

I have a JSON file and want to select and update some parts of it. after using LINQ query to extract some values, get Platform not supported error. but same code works correctly in .Net framework 4.6.

Json file:

  {
  "server": {
    "name": "Server Service",
  },
  "hosts": [
    {
      "id": 0    
    },

    {
      "id": 1000,  
    },
    {
      "id": 1001,    
    },
    {
      "id": 1003,      
    }

  ]
}

C# code:

var xd = json["hosts"].Select(x => ((JObject)x)["Id"]).ToList();
2

There are 2 best solutions below

0
On

Id you are trying to take should be in camelCase.

Json file:

{
  "server": {
    "name": "Server Service",
  },
  "hosts": [
    {
      "id": 0    
    },

    {
      "id": 1000,  
    },
    {
      "id": 1001,    
    },
    {
      "id": 1003,      
    }

  ]
}

C# code:

var xd = json["hosts"].Select(x => ((JObject)x)["id"]).ToList();
0
On

@t-prisar I've used system.json nuget in .net core and it worked for me