龙空技术网

VB6PlusTLB版 – CreateXML函数

vb6plus 87

前言:

此刻朋友们对“vb60 json”都比较看重,同学们都需要了解一些“vb60 json”的相关知识。那么小编在网上收集了一些对于“vb60 json””的相关文章,希望姐妹们能喜欢,看官们快快来学习一下吧!

说明

创建高性能XML解析。

语法

CreateXML() As XML

XML的成员

解析字符串

Function Parse(Text As String, Err As String) As Boolean

Text

字符串

Err

错误信息

解析文件

Function ParseFile(FileName As String, Err As String) As Boolean

FileName

文本文件。支持ANSI/UTF-16 LE/UTF-16 BE/UTF-8/带有BOM的UTF-8文件格式

Err

错误信息

得到长度

Function GetLength() As Integer

得到数组的键值(非数组取当前)

Function Rs(Index As Integer, Key As String, [DecodeUnicode As Boolean = False], [DataType As VbXMLDataType = vbXML]) As String

Index

数组从0开始的序号

Key

DecodeUnicode

Unicode解码

DataType

返回值格式vbXML,vbJson

得到子数组的长度(非数组返回1)

Function SRsLen(Index As Integer, Key As String) As Integer

Index

数组从0开始的序号

Key

得到子数组的键值(非数组取当前)

Function SRs(Index As Integer, Key As String, SonIndex As Integer, SonKey As String , [DecodeUnicode As Boolean = False], [DataType As VbXMLDataType = vbXML]) As String

Index

数组从0开始的序号

Key

SonIndex

子数组从0开始的序号

SonKey

DecodeUnicode

Unicode解码

DataType

返回值格式vbXML,vbJson

得到指定路径的键值

Function Get(Path As String, [DecodeUnicode As Boolean = False], [DataType As VbXMLDataType = vbXML]) As String

Path

路径

DecodeUnicode

Unicode解码

DataType

返回值格式vbXML,vbJson

示例

新建工程,添加窗体,设置标题,添加标签、文本框和按钮

打开代码窗口,写入代码

Option Explicit

Private Sub cmdJGet_Click()

Dim tXML As XML

Dim StrB As StringBuilder

Dim intLen As Integer

Dim i As Integer

Dim DataType As VbXMLDataType

Dim bolUnicodeDecode As Boolean

Dim StrErr As String

If ckJson.Value = 1 Then

DataType = vbJson

Else

DataType = vbXML

End If

bolUnicodeDecode = IIf(ckUnicodeDecode.Value = 1, True, False)

Set StrB = CreateStringBuilder

StrB.Append2 "----------------------", vbCrLf

StrB.Append2 "按路径读取", vbCrLf

StrB.Append2 "路径:" & txtPath.Text, vbCrLf

StrB.Append2 "----------------------", vbCrLf

Set tXML = CreateXML

If tXML.Parse(TextBox1.Text, StrErr) = False Then

StrB.Append2 StrErr, vbCrLf

Set tXML = Nothing

GoTo Final

End If

StrB.Append tXML.Get(txtPath.Text, bolUnicodeDecode, DataType)

Set tXML = Nothing

Final:

TextBox2.Text = StrB.ToString

Set StrB = Nothing

End Sub

Private Sub cmdParseXML_Click()

Dim tXML As XML

Dim StrB As StringBuilder

Dim intLen As Integer

Dim i As Integer

Dim DataType As VbXMLDataType

Dim bolUnicodeDecode As Boolean

Dim StrErr As String

If ckJson.Value = 1 Then

DataType = vbJson

Else

DataType = vbXML

End If

bolUnicodeDecode = IIf(ckUnicodeDecode.Value = 1, True, False)

Set StrB = CreateStringBuilder

StrB.Append2 "----------------------", vbCrLf

StrB.Append2 "Row解析", vbCrLf

StrB.Append2 "----------------------", vbCrLf

Set tXML = CreateXML

If tXML.Parse(TextBox1.Text, StrErr) = False Then

StrB.Append2 StrErr, vbCrLf

Set tXML = Nothing

GoTo Final

End If

intLen = tXML.SRsLen(0, "row")

StrB.Append6 "序号", vbTab, "名称", vbTab, "值", vbCrLf

For i = 1 To intLen

StrB.Append6 CStr(i), vbTab, tXML.SRs(0, "row", i - 1, "name", bolUnicodeDecode, DataType), vbTab, tXML.SRs(0, "row", i - 1, "value", bolUnicodeDecode, DataType), vbCrLf

Next

Set tXML = Nothing

Final:

TextBox2.Text = StrB.ToString

Set StrB = Nothing

End Sub

运行效果免责声明

Vb6plusTLB库,使用社区版开发,仅供学习交流使用。

使用本软件风险由用户自行承担,在适用法律允许的最大范围内,对因使用或不能使用本软件所产生的损害及风险,包括但不限于直接或间接的个人损害、商业盈利的丧失、贸易中断、商业信息的丢失或任何其它经济损失,以及任何不可抗力带来的损失,我方不承担任何责任。

如本文不适合发表请通知删除。

标签: #vb60 json