reCaptcha - 阅读JSON响应

时间:2017-02-20 14:11:10

标签: asp.net json recaptcha

我从reCapture获得响应并需要读取“成功”值,但得到错误:

Public member 'success' on type 'Dictionary(Of String,Object)' not found.

响应

{“success”:true,“challenge_ts”:“2017-02-20T13:55:01Z”,“hostname”:“domain.co.uk”}

我正在尝试使用以下方式访问它:

data.success

完整代码

Dim Response As String = Request.Form("g-recaptcha-response")
Dim Valid As Boolean = False
Dim req As HttpWebRequest = DirectCast(WebRequest.Create(Convert.ToString("https://www.google.com/recaptcha/api/siteverify?secret=" & SecretKey & "&response=") & Response), HttpWebRequest)
Try
    Using wResponse As WebResponse = req.GetResponse()

        Using readStream As New StreamReader(wResponse.GetResponseStream())
            Dim jsonResponse As String = readStream.ReadToEnd()
            Dim js As New JavaScriptSerializer()
            Dim data As Object = js.Deserialize(Of Object)(jsonResponse)
            Valid = Convert.ToBoolean(data.success)
        End Using
    End Using

    Return Valid
Catch ex As WebException
    Throw ex
End Try

1 个答案:

答案 0 :(得分:0)

最后得到了答案,以防这对任何人都有帮助:

data("success")

而不是

data.success