如何把数组中的内容全部输出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 中,这样只能提取最后一条记录