Good day, the problem with parsing JSON.
I use JSON.NET for parsing.

Input data:

{"response": [{"uid": 12345, "first_name": "First Name", "last_name": "Last Name", "hidden": 1}]}

var res = Make("https://api.vk.com/method/users.get?user_ids=" + Config.UserId); //Make делает GET-запрос и возвращает результат. (Верный результат на месте, проверено) var r = JsonConvert.DeserializeObject(res); MessageBox.Show(r.response.first_name); 

On MessageBox.Show () throws an error:

"Newtonsoft.Json.Linq.JArray" does not contain a definition for "first_name"

  • and this is logical - the array has no properties, you need to take the property of a specific element of the array, for example r.response[0].first_name - Grundy
  • Thank you, I understand what's in the cant! - AGrief
  • @Grundy translate your comment into a reply. - andreycha

2 answers 2

in json - response is an array, respectively, it is also parsed into an array. And since the array has no properties, you need to take the property of a specific element of the array, for example

 r.response[0].first_name 

    {"response": [{"uid": 12345, "first_name": "First Name", "last_name": "Last Name", "hidden": 1}]}

    To get response => first_name, you must use the code:

     //правильный вариант var json = r.response[0].first_name; //не правильный вариант! var json = r.response.first_name; //почему же он не верен? reponse в данном JSON - это массив и мы обращаемся к самому первому элементу, т.е. с индексом 0 
    • it is better to explain why the second option is wrong :-) - Grundy