【发布时间】:2020-05-23 02:50:44
【问题描述】:
我有一个包含各种 JSON 数组的 Html 页面。我正在使用 HTML Agility Pack 从页面中获取 innerText,它隔离了页面中的一些剩余文本和 JSON 数组(页面中有许多复杂的对象)。然后我将文本传递给正则表达式,如下所示,它解析键/值对;但是它停在撇号处;但是我需要它并希望保留特殊字符以支持其他功能。
我从互联网上获取 RegEx,我确信它需要调整以允许特殊字符。我尝试了各种方法;但不是正则表达式的专家,我无法提出解决方案。有人对如何修复 RegEx 有一些建议吗?
Dim some_json As String = """{""request"":""Over the last 25 years, I've worked with most of the world’s leading selling strategy systems and built sales training used by companies on six continents. Two years ago, I teamed up with other sales strategy experts to merge our combined experience, wisdom and knowledge into an artificial intelligence system. We worked with expert neuroscientists, behavioral economists, psychologists, and AI programmers to develop JOY, the world’s first emotionally intelligent and sales-savvy artificial intelligence system for sales. Now I focus on helping companies implement JOY to instantly increase sales and dominate markets. \n "",""status"":200}"""
some_json = some_json.Replace("\n", " ")
Dim r As Regex = New Regex("""(?<Key>[\w]*)"":""?(?<Value>([\s\w\d\.\\\-/:_\+]+(,[,\s\w\d\.\\\-/:_\+]*)?)*)""?")
Dim mc As MatchCollection = r.Matches(some_json)
'regex returns summary: Over the last 25 years, I
'how do I return the entire value with the apostrophe's, special characters?
For Each k As Match In mc
Try
If (k.Groups("Value").Value.Length > 0 And k.Groups("Key").Value = "request") Then
m = m & k.Groups("Key").Value & ":" & k.Groups("Value").Value.ToString & "<br/><br/>"
End If
Catch ex As Exception
Dim se As String = ex.Message
End Try
Next
Response.Write(m)
【问题讨论】: