添加条件以将 ID 与 JSON 匹配

问题描述

enter image description here

如果匹配,我试图在 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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...