Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌recaptcha(第2版)回应_Javascript_Node.js_Handlebars.js_Recaptcha - Fatal编程技术网

Javascript 谷歌recaptcha(第2版)回应

Javascript 谷歌recaptcha(第2版)回应,javascript,node.js,handlebars.js,recaptcha,Javascript,Node.js,Handlebars.js,Recaptcha,您如何处理来自google的JSON响应 这就是我获取JSON的方式: res.on('data', function (chunk) { //process.stdout.write(chunk);//formats it like I need it var lines =JSON.parse(chunk); }); 我从谷歌得到的信息(例如),谷歌JSON的外观: { success: false, 'error-codes': [ '

您如何处理来自google的JSON响应

这就是我获取JSON的方式:

 res.on('data', function (chunk) {
            //process.stdout.write(chunk);//formats it like I need it

            var lines =JSON.parse(chunk);
});
我从谷歌得到的信息(例如),谷歌JSON的外观:

{ success: false, 'error-codes': [ 'missing-input-response' ] }
我认为有效的方法是:

JSON.parse("{ success: false, 'error-codes': [ 'missing-input-response' ] }").success;
当然,它不起作用,因为它的格式不正确

实际可行的方法(但为此我需要从google转换JSON):

然后我发现:

但这在我的位置上似乎不起作用,也许他们将JSON从recaptcha版本1更改为版本2

已更新

更深入的研究表明:


看起来JSON可能已经为您解析过了<代码>{success:false,'error code':['missing input response']}是Node.js打印对象的方式。

好的,这解决了我的问题:

JSON.parse(blal.replace(/\n|\r/g, "")).success;
假设
blal
是谷歌的JSON

var req = http.request(options, function(res) {
  res.setEncoding('utf8');
  res.on('data', function(chunk) {//chunk is the JSON from google
    var lines = chunk.split("\n");
    if(lines.length >= 2) {
        if(lines[0] == 'true')
            that._recaptcha_response.is_valid = true;
        that._recaptcha_response.error = lines[1];
    }
    that.emit('data', that._recaptcha_response);
  });
});
JSON.parse(blal.replace(/\n|\r/g, "")).success;