You should define a type to store your data:
public class MyData
{
[JsonProperty("ids")] // not strictly necessary*
public int[] Ids { get; set; }
}
Using the JSON.NET NuGet package:
string json = "{\"ids\":[1,2,3,4,5]}";
MyData result = JsonConvert.DeserializeObject<MyData>(json);
int[] ids = result.Ids;
Using the System.Text.Json NuGet package:
string json = "{\"ids\":[1,2,3,4,5]}";
MyData result = JsonSerializer.Deserialize<MyData>(json);
int[] ids = result.Ids;
* The JsonProperty
attribute exists in both packages. It's not strictly necessary for your code as they should both handle case sensitivity issues by default, but it's useful to know about for situations where you don't necessarily have the same C# property names as JSON names.