I like to get the first value of JSON array.
My JSON:
{
"userlist": [
{
"id": 123,
"name": "Max",
}
],
}
What I have:
public int JSONId(string JSONstring)
{
JObject responseJSON = JObject.Parse(ResponseGETSearchForCorrectID);
int id = (int)JArray.Parse(ResponseGETSearchForCorrectID).Children()["userlist"]["id"].First();
return id;
}
But I get this error: Newtonsoft.Json.JsonReaderException: 'Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject. Path '', line 1, position 1.'
I tried also:
int idPackage = responseJSON["userlist"]["id"].Values;
But doesn`t work too because I get an exception with the info, that this is an array.
What I do wrong here? Have someone a soulution?
Thank you.