I have a challenge to parse the Json data received from the server machine in both parent and child tables. Currently I'm only managing to parse into the parent table, the child table the issue is iterate the received Json which looks exactly below
Json Data received from the server
Here is the VBA I used to iterate for the Parent table:
The remainder json below is for Child table.
Json Data received from the server
JSON:
{
"ESDTime": "20180101203450",
"TerminalID": "30100000005",
"InvoiceCode": "110001803014",
"InvoiceNumber": "000070001",
"FiscalCode": "11298303812903938000",
"Operator": "Admin",
"TaxItems": [
{
"TaxLabel": "A",
"CategoryName": "Standard Rate",
"Rate": 0.16,
"TaxAmount": 20.98
},
{
"TaxLabel": "B",
"CategoryName": "MTV",
"Rate": 0.12,
"TaxAmount": 16.77
}
],
"TotalAmount": 289.12,
"VerificationUrl": "www.nectorprime.Org"
}
Here is the VBA I used to iterate for the Parent table:
Code:
Dim lngStatus As Long
Dim strError As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim json As Object
Dim strData As String
Dim Details As Variant
Dim Z As Long
' Read maximum of 4896 bytes from serial port.
lngStatus = CommRead(intPortID, strData, 4896)
'Processing data from the string above
Set db = CurrentDb
Set rs = db.OpenRecordset("tblInvoiceHeaders", dbOpenDynaset)
Set json = JsonConverter.ParseJson(strData)
'Process data.
Z = 1
For Each Details In json
rs.AddNew
rs![ESDTime] = Details("ESDTime")
rs![TerminalID] = Details("TerminalID")
rs![InvoiceCode] = Details("InvoiceCode")
rs![InvoiceNumber] = Details("InvoiceNumber")
rs![FiscalCode] = Details("FiscalCode")
rs.Update
Z = Z + 1
Next
rs.Close
Set rs = Nothing
Set db = Nothing
Set json = Nothing
Set Details = Nothing
The remainder json below is for Child table.
Code:
"TaxItems": [
{
"TaxLabel": "A",
"CategoryName": "Standard Rate",
"Rate": 0.16,
"TaxAmount": 20.98
},
{
"TaxLabel": "B",
"CategoryName": "MTV",
"Rate": 0.12,
"TaxAmount": 16.77
}
],
Attachments
Last edited: