我正在使用Classic ASP "ASP JSON“类来处理Mandrill Email API上的JSON数据。
这是我目前正在编写的代码:
<%
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,"]","")
%>我不知道如何判断"vAnswerRej“是否包含数据。
我尝试了以下选项来检查变量是否为空:
if len(vAnswerRej) > 0 then....和
if vAnswerRej <> "" then但返回数据的长度始终为零,即使它确实包含数据,因为如果"vAnswerRej“为空,则responseText错误后的Replace()行也是如此。
有没有简单的方法来确认JSON responseText是否包含一些JSON数据?
我假设它与使用JSON数据有关,并且该对象不会被视为常规的字符串变量,但我不知道如何检查它是否为空。
任何建议都非常感谢。
谢谢!
发布于 2014-03-03 18:27:20
尝试执行以下操作以捕获所有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像这样使用它:
if Not IsNullOrEmpty(vAnswerRej) then ...发布于 2014-03-04 16:53:18
关于我在OP问题中的评论
我发现的简单方法(尽管我将其归类为hack)是使用
If Len(vAnswerRej & "") > 0 Then已经用了很多年了。
https://stackoverflow.com/questions/22140172
复制相似问题