Решил, выбросив RegEx, и использовал рекурсивную функцию, чтобы вытянуть что-нибудь с любой глубины json. Он выводит пары имя / значение. Если есть глубокий объект, он складывает имена ключей (например, глубину4.depth3.depth2) и затем следует со значением. Так что простая строка сравнивает ключ (комбинированный), и вы можете извлечь значение.
Private Shared Function ParseJson(ByVal token As JToken, ByVal nodes As Dictionary(Of String, String), ByVal Optional parentLocation As String = "") As Boolean
If token.HasValues Then
For Each child As JToken In token.Children()
If token.Type = JTokenType.[Property] Then
If parentLocation = "" Then
parentLocation = (CType(token, JProperty)).Name
Else
parentLocation += "." & (CType(token, JProperty)).Name
End If
End If
ParseJson(child, nodes, parentLocation)
Next
Return True
Else
If nodes.ContainsKey(parentLocation) Then
nodes(parentLocation) += "|" & token.ToString()
Else
nodes.Add(parentLocation, token.ToString())
End If
Return False
End If
End Function
Использование:
Private Sub Test_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim ServerPath As String = HttpRuntime.AppDomainAppPath
Dim left_overs As String = String.Empty
'download web page
Dim html = New HtmlDocument()
html.LoadHtml(New WebClient().DownloadString(ServerPath & "files/somefile.htm"))
Dim txt As String = html.DocumentNode.InnerText, m As String = String.Empty
Try
Dim ndes As Array = html.DocumentNode.SelectNodes("//cde").ToArray
For Each item As HtmlNode In ndes
Dim s As String = item.InnerText.Trim
'Response.Write(s)
Try
Dim nodes As Dictionary(Of String, String) = New Dictionary(Of String, String)()
Dim rootObject As JObject = JObject.Parse(s)
ParseJson(rootObject, nodes)
For Each key As String In nodes.Keys
If key = "included.summary" Then
left_overs = AlphaNumericOnly(nodes(key))
m = m & key & " = " & left_overs & "<br/><br/>"
Response.Write(m)
End If
Next
Catch ex As Exception
Dim err As String = ex.Message
End Try
Next
Catch ex As Exception
End Try
End Sub
И немного функции очистки.
Public Shared Function AlphaNumericOnly(strSource As String) As String
Dim i As Integer
Dim strResult As String = String.Empty
For i = 1 To Len(strSource)
Select Case Asc(Mid(strSource, i, 1))
Case 32 To 91, 93 To 126 'include 32 if you want to include space
strResult = strResult & Mid(strSource, i, 1)
End Select
Next
AlphaNumericOnly = strResult
End Function