如何规避电子政务门户网站建设的教训,马鞍山人才网,什么软件做电影短视频网站,网站制作的前期主要是做好什么工作这个代码写的有点时间了#xff0c;可能有点小bug#xff0c;欢迎评论区反馈
作用是将Json文本转化成一个HarryNode类进行相关的Json对象处理或者读取#xff0c;也可以将一个HarryNode对象用ToString变为Json文本。
举例#xff1a;
1、读取节点数据
dim harryNode N…这个代码写的有点时间了可能有点小bug欢迎评论区反馈
作用是将Json文本转化成一个HarryNode类进行相关的Json对象处理或者读取也可以将一个HarryNode对象用ToString变为Json文本。
举例
1、读取节点数据
dim harryNode New HarryNode(, {msg:hello world!})
msgbox(harryNode.GetAtt(msg)) 弹窗显示hello world!下面展示更复杂的嵌套读取
dim harryNode New HarryNode(, {node1: {msg:hello world!}})
msgbox(harryNode.GetAtt(node1.msg)) 弹窗显示hello world! 没错用“.”作为路径连接符进行寻址如果json的键里包含“.”可以将源码里的“.”替换成其它字符也可以这样进行取值
msgbox(harryNode.GetAtt(node1)(msg).value
这里的harryNode.GetAtt(node1)返回的是一个字典对象String, HarryNode
2、创建新Json节点写入数据并输出文本
Dim harryNode New HarryNode(, {})
harryNode.SetAtt(msg, hello world!)
MsgBox(harryNode.ToString)可以看到SetAtt方法的第二个参数输入的字符串需要是json字符串格式因此字符串本身需要加双引号
下面可以用SetAtt的另一种重载方法与上面代码的结果相同
harryNode.SetAtt(msg, hello world!, NodeTypeEnum.isString)
MsgBox(harryNode.ToString)同样对嵌套的复杂json对象可以如下
harryNode.SetAtt(node1.msg, hello world!, NodeTypeEnum.isString)
下面这样写也是可以的
harryNode.SetAtt(node1, {msg: hello world!})
文档
1、方法和函数
New
构造函数
nameString节点的名字对于根节点此项没啥意义jsonString要解析构造的JSON串parentHarryNode实例的父节点
nameString节点的名字对于根节点此项没啥意义nodeValueObject节点VB.NET对象值typeNodeTypeEnum节点值的类型parentHarryNode实例的父节点
GetAtt
获得指定路径的VB.NET对象
pathString节点路径defaultValueObject没有获取到返回的值默认Nothing
SetAtt
根据指定路径设置节点值
pathString节点路径newValueObject节点的值VB.NET对象newValueTypeNodeTypeEnum值的类型 pathString节点路径jsonString节点的值JSON字符串 ReName
重命名某个节点
pathString节点路径newNameString新名字
ToJson
返回JSON字符串与ToString()等价
GetNode
获得指定路径的HarryNode对象
pathString节点路径
AddNode
添加子节点
pathString节点路径nodeNameString子节点名nodeJsonString子节点JSON串
Del
删除指定路径的节点
pathString节点路径
Merge
合并两个字典节点
nodeHarryNode要合并的节点
GetChildPath
返回一个当前节点子节点名的列表
Add
指定某个节点的数据加一个值
pathString节点路径addValueSingle加数
ConAdd
指定某个节点的数据加一个值但是限制了数的范围
pathString节点路径addValueSingle加数maxValueSingle最大值minValueSingle最小值默认0
Mul
指定某个节点的数据乘一个值
pathString节点路径addValueSingle乘数
Power
指定某个节点的数据求次幂 pathString节点路径addValueSingle幂 2、属性
Value
当前节点的VB.NET类型值 3、事件
NodeContentChangeBefore
节点内容改变之前
pathString节点路径newValueObject即将变成的值newValueTypeNodeTypeEnum即将变成值的类型
NodeContentChangeBeforeFromJson
节点内容改变之前通过JSON解释
pathString节点路径jsonString即将变成的值的JSON字符串
NodeContentChangeLater
节点内容改变之后
pathString节点路径newValueObject变成的值newValueTypeNodeTypeEnum变成值的类型 NodeContentChangeLaterFromJson
节点内容改变之后通过JSON解释
pathString节点路径jsonString变成的值的JSON字符串
源码如下
Imports System.Text.RegularExpressions
Public Class HarryNodePublic Shared pathSeparator As String .Public Shared outputFormat As Boolean TruePublic Shared formatRetraction As Integer 2Public Shared Function MulReplace(source As String, ParamArray args() As String) As StringIf args.Length Mod 2 0 ThenReturn sourceEnd IfFor i As Integer 0 To UBound(args) Step 2source Replace(source, args(i), args(i 1))NextReturn sourceEnd FunctionPublic Shared Function ToEscape(source As String) As StringReturn MulReplace(source, \, \\, vbCrLf, \n, vbTab, \t, , \, Chr(8), \b, Chr(12), \f)End FunctionPublic Enum NodeTypeEnumisNull 0isString 1isSingle 2isDict 3isList 4isBool 5End EnumPublic nodeType As NodeTypeEnumPublic nodeName As StringPublic parentNode As HarryNodePrivate stringValue As StringPrivate singleValue As SinglePrivate boolValue As BooleanPrivate childNode As Dictionary(Of String, HarryNode)Public Event NodeContentChangeBefore(ByRef path As String, ByRef newValue As Object, ByRef newValueType As String)Public Event NodeContentChangeBeforeFromJson(ByRef path As String, ByRef json As String)Public Event NodeContentChangeLater(path As String, ByRef nowValue As Object, ByRef newValueType As NodeTypeEnum)Public Event NodeContentChangeLaterFromJson(path As String, nowJson As String)Public Sub Merge(node As HarryNode)If nodeType node.nodeType And nodeType NodeTypeEnum.isDict ThenFor i 0 To node.childNode.Count - 1Dim key node.childNode.Keys(i)If childNode.ContainsKey(key) ThenchildNode(key).Merge(node.childNode(key))ElsechildNode.Add(key, node.childNode(key))End IfNextEnd IfEnd SubPublic Function GetChildPath() As List(Of String)Dim result As New List(Of String)If nodeType NodeTypeEnum.isDict Or nodeType NodeTypeEnum.isList Thenresult.AddRange(childNode.Keys)Elseresult.Add(nodeName)End IfReturn resultEnd FunctionPublic Function GetTreeNode(interpreter As 解释器) As TreeNode Dim rootNode As New TreeNode(nodeName interpreter.Search(nodeName)) If nodeType NodeTypeEnum.isDict Or nodeType NodeTypeEnum.isList Then For Each cNode In childNode rootNode.Nodes.Add(cNode.Value.GetTreeNode(interpreter)) Next Else rootNode.Nodes.Add(Value interpreter.Search(Value)) End If Return rootNodeEnd FunctionPublic Sub Power(path As String, addValue As Single)SetAtt(path, GetAtt(path, 0) ^ addValue, 0)End SubPublic Sub Add(path As String, addValue As Single)SetAtt(path, GetAtt(path, 0) addValue, 0)End SubPublic Sub ConAdd(path As String, addValue As Single, maxValue As Single, Optional minValue As Single 0)Dim newValue As Single GetAtt(path, 0) addValueIf newValue maxValue ThennewValue maxValueEnd IfIf newValue minValue ThennewValue minValueEnd IfSetAtt(path, newValue, 0)End SubPublic Sub Mul(path As String, addValue As Single)SetAtt(path, GetAtt(path, 0) * addValue, 0)End SubPublic Sub AddNode(path As String, nodeName As String, nodeJson As String)Dim paths() As String path.Split(pathSeparatorDim p As StringDim node As HarryNode MeFor i As Integer 0 To UBound(paths) - 1p paths(i)Select Case node.nodeTypeCase NodeTypeEnum.isDict, NodeTypeEnum.isListIf node.nodeType NodeTypeEnum.isList Thenp Int(Val(p))End IfIf Not node.childNode.ContainsKey(p) Thennode.childNode.Add(p, New HarryNode(p, {}, Me))End IfCase Elsenode.nodeType NodeTypeEnum.isDictnode.childNode New Dictionary(Of String, HarryNode)If Not node.childNode.ContainsKey(p) Thennode.childNode.Add(p, New HarryNode(p, {}, Me))End IfEnd Selectnode node.childNode(p)Nextp paths.LastSelect Case node.nodeTypeCase NodeTypeEnum.isDict, NodeTypeEnum.isListIf node.nodeType NodeTypeEnum.isList Thenp Int(Val(p))End IfIf Not node.childNode.ContainsKey(p) Thennode.childNode.Add(p, New HarryNode(p, {}, Me))End IfCase Elsenode.nodeType NodeTypeEnum.isDictnode.childNode New Dictionary(Of String, HarryNode)If Not node.childNode.ContainsKey(p) Thennode.childNode.Add(p, New HarryNode(p, {}, Me))End IfEnd SelectIf Not node.childNode.ContainsKey(p) Thennode.childNode.Add(p, New HarryNode(nodeName, nodeJson, Me))Elsenode.childNode(p) New HarryNode(nodeName, nodeJson, Me)End IfEnd SubPublic Sub Del(path As String)Dim paths() As String path.Split(pathSeparatorDim p As StringDim node As HarryNode MeFor i As Integer 0 To UBound(paths) - 1p paths(i)Select Case node.nodeTypeCase NodeTypeEnum.isDict, NodeTypeEnum.isListIf node.nodeType NodeTypeEnum.isList Thenp Int(Val(p))End IfIf Not node.childNode.ContainsKey(p) ThenReturnEnd IfCase Elsenode.nodeType NodeTypeEnum.isDictnode.childNode New Dictionary(Of String, HarryNode)If Not node.childNode.ContainsKey(p) ThenReturnEnd IfEnd Selectnode node.childNode(p)Nextp paths.LastSelect Case node.nodeTypeCase NodeTypeEnum.isDict, NodeTypeEnum.isListIf node.nodeType NodeTypeEnum.isList Thenp Int(Val(p))End IfIf Not node.childNode.ContainsKey(p) ThenReturnEnd IfCase Elsenode.nodeType NodeTypeEnum.isDictnode.childNode New Dictionary(Of String, HarryNode)If Not node.childNode.ContainsKey(p) ThenReturnEnd IfEnd Selectnode.childNode.Remove(p)End SubPublic Function GetAtt(path As String, Optional defaultValue As Object Nothing) As ObjectIf path ThenReturn ValueEnd IfDim paths() As String path.Split(pathSeparatorDim node As HarryNode MeFor Each p As String In pathsSelect Case node.nodeTypeCase NodeTypeEnum.isDict, NodeTypeEnum.isListIf node.childNode.ContainsKey(p) Thennode node.childNode(p)ElseReturn defaultValueEnd IfCase ElseReturn defaultValueEnd SelectNextReturn node.ValueEnd FunctionPublic Function GetNode(path As String) As HarryNodeIf path ThenReturn MeEnd IfDim p As StringDim paths() As String path.Split(pathSeparatorDim node As HarryNode MeFor i As Integer 0 To UBound(paths) - 1p paths(i)Select Case node.nodeTypeCase NodeTypeEnum.isDict, NodeTypeEnum.isListIf node.childNode.ContainsKey(p) Thennode node.childNode(p)ElseReturn New HarryNode(, , Me)End IfCase ElseReturn New HarryNode(, , Me)End SelectNextIf node.childNode IsNot Nothing AndAlso node.childNode.ContainsKey(paths.Last) ThenReturn node.childNode(paths.Last)End IfReturn New HarryNode(paths.Last, String.Format({0}, paths.Last), Me)End FunctionPublic Sub SetAtt(path As String, newValue As Object, newValueType As String)RaiseEvent NodeContentChangeBefore(path, newValue, newValueType)Dim paths() As String path.Split(pathSeparatorDim p As StringDim node As HarryNode MeFor i As Integer 0 To UBound(paths) - 1p paths(i)Select Case node.nodeTypeCase NodeTypeEnum.isDict, NodeTypeEnum.isListIf node.nodeType NodeTypeEnum.isList Thenp Int(Val(p))End IfIf Not node.childNode.ContainsKey(p) Thennode.childNode.Add(p, New HarryNode(p, {}, Me))End IfCase Elsenode.nodeType NodeTypeEnum.isDictnode.childNode New Dictionary(Of String, HarryNode)If Not node.childNode.ContainsKey(p) Thennode.childNode.Add(p, New HarryNode(p, {}, Me))End IfEnd Selectnode node.childNode(p)Nextp paths.LastSelect Case node.nodeTypeCase NodeTypeEnum.isDict, NodeTypeEnum.isListIf node.nodeType NodeTypeEnum.isList Thenp Int(Val(p))End IfIf Not node.childNode.ContainsKey(p) Thennode.childNode.Add(p, New HarryNode(p, newValue, newValueType, Me))End IfCase Elsenode.nodeType NodeTypeEnum.isDictnode.childNode New Dictionary(Of String, HarryNode)If Not node.childNode.ContainsKey(p) Thennode.childNode.Add(p, New HarryNode(p, newValue, newValueType, Me))End IfEnd Selectnode.childNode(p).Value newValueRaiseEvent NodeContentChangeLater(path, node.childNode(p).Value, node.nodeType)End SubPublic Sub ReName(path As String, newName As String)Dim paths() As String path.Split(pathSeparatorDim p As StringDim node As HarryNode MeFor i As Integer 0 To UBound(paths) - 1p paths(i)Select Case node.nodeTypeCase NodeTypeEnum.isDict, NodeTypeEnum.isListIf node.nodeType NodeTypeEnum.isList Thenp Int(Val(p))End IfIf Not node.childNode.ContainsKey(p) Thennode.childNode.Add(p, New HarryNode(p, {}, Me))End IfCase Elsenode.nodeType NodeTypeEnum.isDictnode.childNode New Dictionary(Of String, HarryNode)If Not node.childNode.ContainsKey(p) Thennode.childNode.Add(p, New HarryNode(p, {}, Me))End IfEnd Selectnode node.childNode(p)Nextp paths.LastSelect Case node.nodeTypeCase NodeTypeEnum.isDict, NodeTypeEnum.isListIf node.nodeType NodeTypeEnum.isList Thenp Int(Val(p))End IfIf node.childNode.ContainsKey(p) Then 修改node.childNode.Add(newName, New HarryNode(newName, node.childNode(p).ToJson, Me))node.childNode.Remove(p)End IfCase Elsenode.nodeType NodeTypeEnum.isDictnode.childNode New Dictionary(Of String, HarryNode)If node.childNode.ContainsKey(p) Thennode.childNode.Add(newName, New HarryNode(newName, node.childNode(p).ToJson, Me))node.childNode.Remove(p)End IfEnd SelectEnd SubPublic Sub SetAtt(path As String, json As String)RaiseEvent NodeContentChangeBeforeFromJson(path, json)Dim paths() As String path.Split(pathSeparatorDim p As StringDim node As HarryNode MeFor i As Integer 0 To UBound(paths) - 1p paths(i)Select Case node.nodeTypeCase NodeTypeEnum.isDict, NodeTypeEnum.isListIf node.nodeType NodeTypeEnum.isList Thenp Int(Val(p))End IfIf Not node.childNode.ContainsKey(p) Thennode.childNode.Add(p, New HarryNode(p, {}, Me))End IfCase Elsenode.nodeType NodeTypeEnum.isDictnode.childNode New Dictionary(Of String, HarryNode)If Not node.childNode.ContainsKey(p) Thennode.childNode.Add(p, New HarryNode(p, {}, Me))End IfEnd Selectnode node.childNode(p)Nextp paths.LastSelect Case node.nodeTypeCase NodeTypeEnum.isDict, NodeTypeEnum.isListIf node.nodeType NodeTypeEnum.isList Thenp Int(Val(p))End IfIf Not node.childNode.ContainsKey(p) Thennode.childNode.Add(p, New HarryNode(p, {}, Me))End IfCase Elsenode.nodeType NodeTypeEnum.isDictnode.childNode New Dictionary(Of String, HarryNode)If Not node.childNode.ContainsKey(p) Thennode.childNode.Add(p, New HarryNode(p, {}, Me))End IfEnd Selectnode.childNode(p).JsonToValue(json)RaiseEvent NodeContentChangeLaterFromJson(path, json)End SubPublic Function ToJson(Optional deep As Integer 1) As StringIf outputFormat ThenDim deepFormatRetraction New String( , deep * formatRetraction)Dim deepFormatRetractionSub1 New String( , (deep - 1) * formatRetraction)Select Case nodeTypeCase NodeTypeEnum.isStringReturn String.Format({0}, ToEscape(stringValue))Case NodeTypeEnum.isBoolReturn boolValue.ToString.ToLowerCase NodeTypeEnum.isSingleReturn singleValueCase NodeTypeEnum.isDictDim result As New List(Of String)For i As Integer 0 To childNode.Count - 1result.Add(String.Format(deepFormatRetraction {0}: {1}, childNode.Keys(i), childNode.Values(i).ToJson(deep 1)))NextReturn String.Format(Replace({{\n{0}\n{1}}}, \n, vbCrLf), Join(result.ToArray, , vbCrLf), deepFormatRetractionSub1)Case NodeTypeEnum.isListDim result As New List(Of String)For i As Integer 0 To childNode.Count - 1result.Add(deepFormatRetraction childNode.Values(i).ToJson(deep 1))NextReturn String.Format(Replace([\n{0}\n{1}], \n, vbCrLf), Join(result.ToArray, , vbCrLf), deepFormatRetractionSub1)Case ElseReturn End SelectEnd IfSelect Case nodeTypeCase NodeTypeEnum.isStringReturn String.Format({0}, ToEscape(stringValue))Case NodeTypeEnum.isBoolReturn boolValueCase NodeTypeEnum.isSingleReturn singleValueCase NodeTypeEnum.isDictDim result As New List(Of String)For i As Integer 0 To childNode.Count - 1result.Add(String.Format({0}:{1}, childNode.Keys(i), childNode.Values(i).ToJson))NextReturn String.Format({{{0}}}, Join(result.ToArray, ,))Case NodeTypeEnum.isListDim result As New List(Of String)For i As Integer 0 To childNode.Count - 1result.Add(childNode.Values(i).ToJson)NextReturn String.Format([{0}], Join(result.ToArray, ,))Case ElseReturn End SelectEnd FunctionPublic Overloads Function ToString() As StringReturn ToJson()End FunctionPublic Property Value() As ObjectGetSelect Case nodeTypeCase NodeTypeEnum.isStringReturn stringValueCase NodeTypeEnum.isBoolReturn boolValueCase NodeTypeEnum.isSingleReturn singleValueCase NodeTypeEnum.isDictReturn childNodeCase NodeTypeEnum.isListReturn childNode.ValuesCase ElseReturn NothingEnd SelectEnd GetSet(value As Object)Select Case nodeTypeCase NodeTypeEnum.isStringstringValue valueCase NodeTypeEnum.isBoolboolValue valueCase NodeTypeEnum.isSinglesingleValue valueCase NodeTypeEnum.isDictchildNode valueCase NodeTypeEnum.isListDim valueList As List(Of HarryNode) valuechildNode.Clear()For i As Integer 0 To valueList.Count - 1childNode.Add(i, valueList(i))NextEnd SelectEnd SetEnd PropertyPublic Sub JsonToValue(json As String)If json Is Nothing ThenReturnEnd Ifjson Regex.Match(json, ^\s*(.*?)\s*$, RegexOptions.Singleline).Groups(1).ValueIf Regex.IsMatch(json, ^.*$, RegexOptions.Singleline) Then字符串nodeType NodeTypeEnum.isStringstringValue json.Substring(1, json.Length - 2)ElseIf Regex.IsMatch(json, ^{.*}$, RegexOptions.Singleline) Then字典nodeType NodeTypeEnum.isDictIf json {} OrElse Regex.IsMatch(json, ^\s*\{\s*\}\s*$) ThenchildNode New Dictionary(Of String, HarryNode)ElsechildNode GetDict(json, Me)End IfElseIf Regex.IsMatch(json, ^\[.*\]$, RegexOptions.Singleline) Then列表nodeType NodeTypeEnum.isListIf json [] OrElse Regex.IsMatch(json, ^\s*\[\s*\]\s*$) ThenchildNode New Dictionary(Of String, HarryNode)ElsechildNode GetList(json, Me)End IfElseIf Regex.IsMatch(json, ^[-]{0,1}[\d]*[\.]{0,1}[\d]*$, RegexOptions.Singleline) Then数值nodeType NodeTypeEnum.isSinglesingleValue Val(json)Else布尔值nodeType NodeTypeEnum.isBoolboolValue GetBool(json)End IfEnd SubPublic Shared Function GetDict(json As String, sourceNode As HarryNode) As Dictionary(Of String, HarryNode)Debug.WriteLine(String.Format(GetDict.json{0}, json))Dim node As New Dictionary(Of String, HarryNode)Dim name As String Dim temp As New List(Of String)Dim bigBrackets As IntegerDim colon As IntegerDim doubleQuotationMark As IntegerDim brackets As IntegerDim escape As IntegerDim stringContent As StringDim exegesis As IntegerFor Each c As String In jsonDebug.WriteLine(Join(temp.ToArray, ))Debug.WriteLine(doubleQuotationMark{0}, doubleQuotationMark)Debug.WriteLine(exegesis{0}, exegesis)Debug.WriteLine(bigBrackets{0}, bigBrackets)Debug.WriteLine(brackets{0}, brackets)Debug.WriteLine()If c / Thenexegesis 1Continue ForElseIf exegesis 1 Thentemp.Add(/)exegesis 0End IfIf exegesis 2 ThenIf c vbCr Or c vbLf Thenexegesis 0ElseContinue ForEnd IfEnd IfIf doubleQuotationMark 0 Then未在字符串内时Select Case cCase {bigBrackets 1If bigBrackets 1 OrElse brackets 0 Then子嵌套记忆temp.Add(c)End IfCase }bigBrackets - 1If bigBrackets 1 OrElse brackets 0 OrElse (bigBrackets 1 AndAlso brackets 0) Thentemp.Add(c)End IfCase [brackets 1temp.Add(c)Case ]brackets - 1temp.Add(c)Case :If bigBrackets 1 AndAlso brackets 0 Then第一层嵌套内colon 1ElseIf bigBrackets 1 OrElse brackets 0 Thentemp.Add(c)End IfCase If bigBrackets 1 AndAlso brackets 0 Then第一层嵌套内doubleQuotationMark 1temp.Add(c)ElseIf bigBrackets 1 OrElse brackets 0 Thentemp.Add(c)End IfCase ,If colon 0 AndAlso bigBrackets 1 AndAlso brackets 0 Then非字符串If temp.Count 0 ThenstringContent Join(temp.ToArray, )temp.Clear()node.Add(name, New HarryNode(name, stringContent, sourceNode))Elsenullnode.Add(name, New HarryNode(name, Nothing, sourceNode))End Ifcolon 0Elsetemp.Add(c)End IfCase ElseIf bigBrackets 1 Or Regex.IsMatch(c, \S, RegexOptions.Singleline) Thentemp.Add(c)End IfEnd SelectElseIf bigBrackets 1 AndAlso brackets 0 Then第一层嵌套内在字符串内Select Case cCase temp.Add(c)If escape 1 Then转义escape 0ElsedoubleQuotationMark 0If colon 0 Then节点名stringContent Join(temp.ToArray, )temp.Clear()name stringContent.Substring(1, stringContent.Length - 2)End IfEnd IfCase \escape 1If escape 1 Then转义\temp.Add(c)escape 0End IfCase nIf escape 1 Then转义换行temp.Add(vbCrLf)escape 0Elsetemp.Add(c)End IfCase bIf escape 1 Thentemp.Add(Chr(8))escape 0Elsetemp.Add(c)End IfCase fIf escape 1 Thentemp.Add(Chr(12))escape 0Elsetemp.Add(c)End IfCase tIf escape 1 Thentemp.Add(vbTab)escape 0Elsetemp.Add(c)End IfCase Elseescape 0temp.Add(c)End SelectEnd IfNextIf temp.Count 0 ThenstringContent Join(temp.ToArray, )temp.Clear()node.Add(name, New HarryNode(name, stringContent, sourceNode))Elsenullnode.Add(name, New HarryNode(name, Nothing, sourceNode))End IfReturn nodeEnd FunctionPublic Shared Function GetList(json As String, sourceNode As HarryNode) As Dictionary(Of String, HarryNode)Debug.WriteLine(String.Format(GetList.json{0}, json))Dim node As New Dictionary(Of String, HarryNode)Dim name As StringDim temp As New List(Of String)Dim bigBrackets As IntegerDim doubleQuotationMark As IntegerDim brackets As IntegerDim escape As IntegerDim comma As IntegerDim stringContent As StringFor Each c As String In jsonDim exegesis As IntegerIf c / Thenexegesis 1Continue ForElseIf exegesis 1 Thentemp.Add(/)exegesis 0End IfIf exegesis 2 ThenIf c vbCr Or c vbLf Thenexegesis 0ElseContinue ForEnd IfEnd IfIf doubleQuotationMark 0 Then未在字符串内时Select Case cCase [brackets 1If brackets 1 OrElse bigBrackets 0 Then子嵌套记忆temp.Add(c)End IfCase ]brackets - 1If brackets 1 OrElse bigBrackets 0 OrElse (brackets 1 AndAlso bigBrackets 0) Thentemp.Add(c)End IfCase {bigBrackets 1temp.Add(c)Case }bigBrackets - 1temp.Add(c)Case If brackets 1 AndAlso bigBrackets 0 Then第一层嵌套内doubleQuotationMark 1temp.Add(c)ElseIf brackets 1 OrElse bigBrackets 0 Thentemp.Add(c)End IfCase ,If bigBrackets 0 AndAlso brackets 1 Thenname commacomma 1If temp.Count 0 ThenstringContent Join(temp.ToArray, )temp.Clear()node.Add(name, New HarryNode(name, stringContent, sourceNode))Elsenullnode.Add(name, New HarryNode(name, Nothing, sourceNode))End IfElsetemp.Add(c)End IfCase ElseIf bigBrackets 1 Or Regex.IsMatch(c, \S, RegexOptions.Singleline) Thentemp.Add(c)End IfEnd SelectElseIf brackets 1 AndAlso bigBrackets 0 Then第一层嵌套内在字符串内Select Case cCase temp.Add(c)If escape 1 Then转义escape 0ElsedoubleQuotationMark 0End IfCase \escape 1If escape 1 Then转义\temp.Add(c)escape 0End IfCase nIf escape 1 Then转义换行temp.Add(vbCrLf)escape 0Elsetemp.Add(c)End IfCase bIf escape 1 Thentemp.Add(Chr(8))escape 0Elsetemp.Add(c)End IfCase fIf escape 1 Thentemp.Add(Chr(12))escape 0Elsetemp.Add(c)End IfCase tIf escape 1 Thentemp.Add(vbTab)escape 0Elsetemp.Add(c)End IfCase Elseescape 0temp.Add(c)End SelectEnd IfNextname commaIf temp.Count 0 Then非字符串stringContent Join(temp.ToArray, )temp.Clear()node.Add(name, New HarryNode(name, stringContent, sourceNode))Elsenullnode.Add(name, New HarryNode(name, Nothing, sourceNode))End IfReturn nodeEnd FunctionPublic Shared Function GetBool(value As String) As BooleanIf value.ToLower false OrElse value 0 ThenReturn FalseEnd IfReturn TrueEnd FunctionPublic Sub New(name As String, json As String, Optional parent As HarryNode Nothing)nodeName nameparentNode parentJsonToValue(json)End SubPublic Sub New(name As String, nodeValue As Object, type As NodeTypeEnum, Optional parent As HarryNode Nothing)nodeName namenodeType typeparentNode parentValue nodeValueEnd Sub
End Class