Question

I am using the Classic ASP "ASP JSON" class to work with JSON data on the Mandrill Email API.

This is the code I'm working on / am stuck on at the moment:

<%
Set oJSONRej = New aspJSON

With oJSONRej.data
.Add "key", KEY
.Add "email", "this@that.com"
End With    

vurl = "https://mandrillapp.com/api/1.0/rejects/list.json"
set xmlhttpRej = CreateObject("MSXML2.ServerXMLHTTP.6.0") 
xmlhttpRej.open "POST", vurl, false 
xmlhttpRej.setRequestHeader "Content-type","application/json"
xmlhttpRej.setRequestHeader "Accept","application/json"

'send JSON data to the API
xmlhttpRej.send oJSONRej.JSONoutput()

'process the response JSON data
vAnswerRej = xmlhttpRej.responseText
vAnswerRej = replace(vAnswerRej,"[","")
vAnswerRej = replace(vAnswerRej,"]","")
%>

I can't work out how to tell if the "vAnswerRej" contains data.

I have tried these options to check if the variable is empty:

if len(vAnswerRej) > 0 then....

and

if vAnswerRej <> "" then

but the length of the returned data is always zero, even if it actually does contain data because the Replace() lines after the responseText error if "vAnswerRej" is empty.

Is there a simple way to confirm if the JSON responseText contains some JSON data?

I presume it's something to do with using JSON data and that the object is not treated like a regular string variable, but I can't work out how to check if it is empty.

Any advice much appreciated.

Thanks!

No correct solution

OTHER TIPS

Try this to capture all Nulls:

Public Function IsNullOrEmpty(strString)
  strString = Trim(strString)

  If IsEmpty(strString) Then
    IsNullOrEmpty = True
    Exit Function
  ElseIf StrComp(strString, "") = 0 Then
    IsNullOrEmpty = True
    Exit Function
  ElseIf IsNull(strString) Then
    IsNullOrEmpty = True
    Exit Function
  Else
    IsNullOrEmpty = False
    Exit Function
  End If
End Function

Use it like this:

if Not IsNullOrEmpty(vAnswerRej) then ...

Further to my comment in the OP question

Simple method I have found (although I'd class it as a hack) is to use

If Len(vAnswerRej & "") > 0 Then

Been using it for years.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top