问题描述
如果匹配,我试图在 Col"B"
和 Col"L"
中创建两个条件,然后从 ID Number
中取出 Col"P"
并在 JSON
中获得结果。
JSON 如下所示:
{"id":16,"sku":"4926","productName":"Diforda","upc":"test","condition":"test","uniqueID":1234,"logsCey":3,"Processing":true,"addedDateTime":"2021-06-22T04:07:35.15","softDelete":false,"newLogno":776655}
该代码将在 JSON 中找到 Processing = True
然后从 JSON 中取出 newLogno
并将其粘贴到 Col"A"
中,如果它是 Row
然后对 False
重复相同的过程。
2nd ID Number from Col"P"
解决方法
Sub Testing()
Const blnAsync As Boolean = True
Dim strUrl As String,strResponse As String,idno As Long
Dim ws As Worksheet,LRow As Long,r As Long
Dim JSON As Object,n As Long
Set ws = Sheet4
LRow = ws.Range("B" & ws.Rows.Count).End(xlUp).Row
Dim objRequest As Object
Set objRequest = CreateObject("MSXML2.XMLHTTP")
For r = 2 To LRow
If ws.Cells(r,"B") <> "" And ws.Cells(r,"L") = "Tenu" Then
idno = ws.Cells(r,"P").Value
strUrl = "URL" & idno
With objRequest
.Open "GET",strUrl,blnAsync
.setRequestHeader "Content-Type","application/json"
.send
While .readyState <> 4
DoEvents
Wend
strResponse = .ResponseText
End With
Set JSON = ParseJson(strResponse)
If JSON("Processing") = True Then
ws.Cells(r,"A").Value = JSON("newLogno")
n = n + 1
End If
End If
Next
MsgBox n & " records found",vbInformation
End Sub