M
M
Mors Clamor2014-06-15 19:26:48
Visual Basic
Mors Clamor, 2014-06-15 19:26:48

VB.Net and XML. Extract values?

It is necessary to pull out first_name and last_name from this into a VB.Net variable.

{"response":[{"uid":238005056,"first_name":"Самый-Лучший","last_name":"День"}]}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Andr, 2016-07-29
@66demon666

Is this not Json for an hour?
Here is a good Open Source library: Json.NET
Documentation
Including , importingImports Newtonsoft.Json.Linq

Dim str = "{'response':[{'uid':238005056,'first_name':'Самый-Лучший','last_name':'День'}]}"

'Парсим Json строку'
Dim JObj As JObject = JObject.Parse(str)
'Парсим значение массив ключа "response"'
Dim JArr As JArray = JArray.Parse(JObj("response").ToString)
'Берём первый элемент массива и парсим как обычную Json строку'
Dim JArrItems As JObject = JObject.Parse(JArr.First.ToString)

'Загоняем в переменные значения ключей "first_name" и "last_name"'
Dim first_name = JArrItems("first_name").ToString,
    last_name = JArrItems("last_name").ToString

Or maybe so
Dim str = "{'response':[{'uid':238005056,'first_name':'Самый-Лучший','last_name':'День'}]}"
Dim JArrItems As JObject = JObject.Parse(JArray.Parse(JObject.Parse(str)("response").ToString).First.ToString)

Dim first_name = JArrItems("first_name").ToString,
    last_name = JArrItems("last_name").ToString

Or in general
Dim str = "{'response':[{'uid':238005056,'first_name':'Самый-Лучший','last_name':'День'}]}"
Dim JObj As JObject = JObject.Parse(str)

Dim first_name = JObj("response")(0)("first_name").ToString,
    last_name = JObj("response")(0)("last_name").ToString

And in .NET 3.5+, you can use LINQ queries themselves

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question