Thanks to advice from here (Looping through JSON using ASPJSON) and here (ASP JSON: Object not a collection), I am starting with a JSON array in Classic ASP:
{"markers": [{
"event":"hard_bounce",
"msg":{
"ts":1365109999,
"subject":"This an example webhook message",
"email":"example.webhook#mandrillapp.com",
"sender":"example.sender#mandrillapp.com",
"tags":[
"webhook-example"
],
"state":"bounced",
"metadata":{
"user_id":111
},
"_id":"exampleaaaaaaaaaaaaaaaaaaaaaaaaa",
"_version":"exampleaaaaaaaaaaaaaaa",
"bounce_description":"bad_mailbox",
"bgtools_code":10,
"diag":"smtp;550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient's email address for typos or unnecessary spaces."
},
"_id":"exampleaaaaaaaaaaaaaaaaaaaaaaaaa",
"ts":1433940242
},
{
"event":"hard_bounce",
"msg":{
"ts":1365109999,
"subject":"This an example webhook message",
"email":"example.webhook#mandrillapp.com",
"sender":"example.sender#mandrillapp.com",
"tags":[
"webhook-example"
],
"state":"bounced",
"metadata":{
"user_id":111
},
"_id":"exampleaaaaaaaaaaaaaaaaaaaaaaaaa1",
"_version":"exampleaaaaaaaaaaaaaaa",
"bounce_description":"bad_mailbox",
"bgtools_code":10,
"diag":"smtp;550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient's email address for typos or unnecessary spaces."
},
"_id":"exampleaaaaaaaaaaaaaaaaaaaaaaaaa1",
"ts":1433940242
}]
}
I am using Classic ASP and ASPJSON (http://www.aspjson.com/).
I can access the "_id" and "ts" values from the loop via:
Set oJSON = New aspJSON
'read the local JSON data
oJSON.loadJSON(str2)
For Each thingy In oJSON.data("markers")
Set this = oJSON.data("markers").item(thingy)
Response.Write _
this.item("_id") & ": " & _
this.item("ts") & "<br>"
Next
However, I am stuck trying to get at the data one level down, in the "msg" section.
I did try:
For Each thingy In oJSON.data("markers")
Set this = oJSON.data("markers").item(thingy)
Response.Write _
this.item("_id") & ": " & _
this.item("ts") & "<br>"
For Each thingy2 In oJSON.data("msg")
Set this2 = oJSON.data("this2").item(thingy2)
Response.Write _
this2.item("subject") & ": " & _
this2.item("diag") & "<br>"
Next
Next
But get this error:
Description: Object not a collection : .
Relating to this line:
For Each thingy2 In oJSON.data("msg")
I guess I am doing something silly, but I am stuck on this one and can't work out how to access that data.
You could access msg, which is a json object, within the loop you already have:
For Each thingy In oJSON.data("markers")
Set this = oJSON.data("markers").item(thingy)
Response.Write _
this.item("_id") & ": " & _
this.item("ts") & "<br>" &_
this.item("msg").item("subject") & ": " &_
this.item("msg").item("diag") & "<br>"
Next
Related
I have an access database which I'm using to create a json POST API to a website utilising Neto (https://developers.neto.com.au/documentation/engineers/api-documentation). I am new to APIs, but have been researching for several months and making progress in understanding how it works. I have managed to get a 200 status response from the request which would indicate the header info (including authentication is correct) but error in relation to the body (I believe).
Code as per below:
Dim reader As New XMLHTTP60
Dim username As String, APIkey As String
Dim strJson As String
strJson = "{" & _
"'Filter': {" & _
"'OrderStatus': 'Pick'," & _
"'OutputSelector': [" & _
"'OrderID'," & _
"'ShippingOption'," & _
"]," & _
"}" & _
"}"
username = "xxx"
APIkey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
reader.Open "POST", "https://www.yoursite.co.nz/do/WS/NetoAPI", False
reader.setRequestHeader "NETOAPI_USERNAME", username
reader.setRequestHeader "NETOAPI_KEY", APIkey
reader.setRequestHeader "Content-Type", "application/json"
reader.setRequestHeader "Accept", "application/json"
reader.setRequestHeader "NETOAPI_ACTION", "GetOrder"
reader.send strJson
Debug.Print reader.Status
Debug.Print reader.responseText
error message:
{"CurrentTime":"2021-09-17 02:42:50","Ack":"Error","Messages":[{"Error":{"Message":"JSON Error","SeverityCode":"Error"},"Warning":{"Message":"Warning","SeverityCode":"Warning","Description":"'\"' expected, at character offset 1 (before \"'Filter': {'OrderSta...\")"}}]}
Initially i am just trying to retrieve 2 pieces of data (OrderID and ShippingOption) for any orders with status of Pick.
i have tried replacing all ' with "" as i've seen in other posts along with a few other variations but with no luck.
Any help would be appreciated. Thanks
You are using single quote instead of double quotes in your JSON
The value of Filter is a collection enclosed with [ ] so I believe you need to wrap Pick as well (despite there's only 1 value).
You have an extra , after ShippingOption when it's the last value so remove that.
Try this instead:
strJSON = "{" & _
"""Filter"": {" & _
"""OrderStatus"": [""Pick""]," & _
"""OutputSelector"": [" & _
"""OrderID""," & _
"""ShippingOption""" & _
"]" & _
"}" & _
"}"
Above will produce the JSON below:
{"Filter": {"OrderStatus": ["Pick"],"OutputSelector": ["OrderID","ShippingOption"]}}
I want to hide or not show Field Names if value is Null, for fields "Location" and "Bin" when updating my eBay webpage Custom Label Fields.
Tried
If IsNull(Me!Location) Then
Me!Location.Visible = False
Else
Me!Location = True
but keep getting errors (Method or data not found or runtime 438) with the following code.
Call IE.Document.getElementById("editpane_skuNumber").setAttribute("value", ([CustomLabelCombine]) & " " & ("Location" & " " & [Location]) & " " & ("Bin" & " " & [Bin]))
If you have a better solution please let me know.
Is IE.Document.GetelementsbyID a subroutine or function? if not, remove the word "call" and replace with
me.Location = IE.Document.getElementById("editpane_skuNumber").setAttribute("value", ([CustomLabelCombine]) & " " & ("Location" & " " & [Location]) & " " & ("Bin" & " " & [Bin]))
If IsNull(Me!Location) Then
Me!Location.Visible = False
Else
Me!Location = True
End IF
Comment1:
When using "Call" you are asking the current procedure to "Call" a public subroutine. Example below
Private Sub Button1_Click()
Call TestRoutine
End Sub
Public Sub TestRoutine()
Msgbox "You clicked Button 1"
End Sub
If you aren't calling another subroutine to execute more coding, then remove the word "Call".
I also noticed your if is missing the .visible after the else for line
Me!Location = true
Should be:
Me!Location.Visible = true
I'm working on an classic ASP-project and I use ASP Xtreme Evolution to parse JSon data (found here: How to access JSON data in classic ASP using json2.asp or aspjson libraries?)
I tried, but I can't. how do i access this json data?
{
"result":[
{
"key":"2607037",
"sts":"finished",
"stsdetail":"Finished",
"sname":"Ice Hockey",
"home":{
"1p":"0",
"fe":"2",
"3p":"1",
"2p":"1",
"ord":"2",
"rs":"2"
},
"away":{
"ord":"0",
"1p":"0",
"rs":"0",
"2p":"0",
"3p":"0",
"fe":"0"
}
},
{
"key":"2435948",
"sts":"finished",
"stsdetail":"Finished",
"sname":"Soccer",
"home":{
"ord":"2",
"rs":"2",
"fe":"2",
"ht":"1"
},
"away":{
"ord":"0",
"rs":"0",
"fe":"0",
"ht":"0"
}
},
{
"key":"2606031",
"sts":"cancelled",
"stsdetail":"Cancelled",
"sname":"Tennis"
}
]
}
code:
set restaurant = oJSON.data("result")
for each itm in restaurant
if Not IsObject(restaurant.item(itm)) then
Response.write itm &" : "& restaurant.item(itm) & "<br/>"
else
'opening
for each dayy in restaurant.item(itm)
Response.write dayy & ":"
Response.write restaurant.item(itm)(dayy)
If restaurant.item(itm)(dayy) <> "" Then
Response.write " - "
Response.write restaurant.item(itm)(dayy)
End If
Response.write "<br/>"
next
end if
you're missing the indexes in the array, try this:
for each dayy in restaurant.item(itm)
Response.write dayy & ":"
Response.write restaurant.item(itm)(dayy)(0)
If restaurant.item(itm)(dayy)(1) <> "" Then
Response.write " - "
Response.write restaurant.item(itm)(dayy)(1)
End If
Response.write "<br/>"
next
I trying to create Add,update,Delete operation on MS Access form.I found this code on internet where Insert and update is happening on the same button. I am not getting what is exactly happening in below line and how it's identifying it is for update or insert.
Not getting following line : = Me.txtid.Tag & "" = ""
Please find below code which works perfect as per requirement.
'When we click on button Add there are two options
'1. for insert
'2. for update
If Me.txtid.Tag & "" = "" Then
' this is for insert new
' add data in table
CurrentDb.Execute "insert into student(stdid,stdname,gender,phone,address)" & _
" values(" & Me.txtid & ",' " & Me.txtname & " ',' " & Me.cmbgender & " ','" & _
Me.txtphone & "', '" & Me.txtaddress & "')"
'refresh data in list on form
subform_student.Form.Requery
Else
CurrentDb.Execute "UPDATE student " & _
" set stdid = " & Me.txtid & _
", stdname = '" & Me.txtname & "' " & _
", gender = '" & Me.cmbgender & " ' " & _
", phone = ' " & Me.txtphone & " ' " & _
", address = ' " & Me.txtphone & " ' " & _
" WHERE stdid = " & Me.txtid.Tag
End If
The .Tag property is a general-purpose string property of every form and control object in VBA/VB6. It is provided as a place for developers to "put stuff" to support the operation of their applications.
The original code from which you copied your sample must have written a value to Me.txtid.Tag when the record was loaded (e.g., perhaps in the form's Current event) to indicate whether the record is an existing record or a new record (empty="new", non-empty="existing"). The line
If Me.txtid.Tag & "" = "" Then
simply checks to see if the .Tag property is empty, and then performs the INSERT or UPDATE accordingly.
BTW, re:
below code which works perfect as per requirement
No, it doesn't. Try adding a record where [stdname] is Tam O'Shanter and see for yourself. You should ditch the dynamic SQL and use one of
a bound form (as Gustav suggests),
a parameterized query, or
a recordset update.
Forget/remove all this code and bind the form to table Student to make this all happen automatically.
If a bound form is not familiar to you, browse for a tutorial for "Beginning with Microsoft Access" or the like.
I am trying to get the value "aaG40a2f-53d3-8f74-3c200403223" from the json code below that's in json.
My vb.net code looks like this:
For Each Row In json("data")("records")("Form")
Try
For rowNum = 0 To result_RowNames.Length - 1
result_rowData(intX) = NullSafeSelect(Row, result_RowNames(rowNum))
Select Case result_RowProperTypes(rowNum)
Case "textField"
_tmpHtml += "<td>" & vbCrLf
_tmpHtml += "<input type=""text"" " & _
"data-first=""yes"" " & _
"data-uid=""" & NullSafeSelect(Row("#uid"), result_RowNames(rowNum)) & """ " & _
"onchange=""updateChange(this);"" " & _
"id=""textbox_" & rowNum & """ " & _
"class=""form-control small"" " & _
"value=""" & result_rowData(intX) & """>" & vbCrLf
......etc etc...
My json in ("data")("records")("Form") looks like this:
{
"#application_uid": "af74c279-4340-8441-2dR4e696gb1",
"#draft_ownerid": "",
"#flowState": "ST_NewName",
"#has_draft": "",
"#id": "63",
"#uid": "aaG40a2f-53d3-8f74-3c200403223",
"F_FName": "test1",
"F_LName": "test2"
}
The code above works - it just does not produce a value for uid as seen below in the output of HTML:
<input type="text" data-first="yes" data-uid="" onchange="updateChange(this);" id="textbox_0" class="form-control small" value="test1">
Looks like all I needed to do was just to use
Dim tmpUID = Row("#uid").ToString
in order to get the value I was looking for.