标题:如何把数组中的内容全部输出text
取消只看楼主
gdpnking
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2020-7-17
结帖率:66.67%
已结贴  问题点数:20 回复次数:0 
如何把数组中的内容全部输出text
Public Function GetPage(url)
Dim Retrieval
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", url, False
.Send
GetPage = BytesToBstr(.ResponseBody)
End With
Set Retrieval = Nothing
End Function

Public Function BytesToBstr(body)
Dim objstream
Set objstream = CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode = 3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = "UTF-8"
BytesToBstr = objstream.ReadText
objstream.Close
Set objstream = Nothing
End Function

Private Sub Command1_Click()
On Error Resume Next
Dim Num As String, time As String, Status As String, sRes As String
'Num = Text1.Text
Num = "78161096634176"
url = "https://api. & Num
Dim iTimeOut As Integer
Dim iTimeOutMax As Integer
Dim aFile As Variant

Dim arrLine As Variant
Dim sLine As String '每行跟踪记录

Dim arrText As Variant
Dim sText As String '在每行跟踪记录中用于分段获取时间和日志

Dim iCnt As Integer

aFile = Split(GetPage(url), """list"":[{")
If UBound(aFile) >= 1 Then

sLine = aFile(1)
arrLine = Split(sLine, "},{")
For iCnt = 0 To UBound(arrLine)
sText = arrLine(iCnt)
arrText = Split(sText, """:""")
If UBound(arrText) >= 2 Then
time = arrText(1)
Status = arrText(2)
time = Rep(time)
Status = Rep(Status)




End If

Next

Text2.Text = "" & Status & vbCrLf & Space(1) & time

sRes = aFile(0)

End If


End Sub

'替换掉无用的字符串
Function Rep(str As String) As String
Dim sRes As String
sRes = Replace(str, """", "")
sRes = Replace(sRes, "{", "")
sRes = Replace(sRes, "}", "")
sRes = Replace(sRes, ",status", "")
sRes = Replace(sRes, ",time", "")
sRes = Replace(sRes, ",deliverystatus", "")
sRes = Replace(sRes, ",issign", "")
sRes = Replace(sRes, "]:0:1", "")
sRes = Replace(sRes, "]:1:1", "")
sRes = Replace(sRes, "]:2:1", "")
sRes = Replace(sRes, "]:3:1", "")
sRes = Replace(sRes, "]:4:1", "")
Rep = sRes
End Function



如何把数组中的Status 和 time  都提取到text2.text 中,这样只能提取最后一条记录
搜索更多相关主题的帖子: time Dim Replace Status String 
2020-12-01 23:04



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-504089-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015237 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved