Javascript json中的意外标记o

Javascript json中的意外标记o,javascript,json,node.js,Javascript,Json,Node.js,我在JSON中得到了这种类型的错误 错误详细信息: [对象] SyntaxError:JSON中位置1处的意外标记o function address_transaction(address,callback) { var api_key='11111111111111'; var type='na'; var url='some url'; var request = require('request'); request(url, function (error, response,

我在JSON中得到了这种类型的错误 错误详细信息:

[对象]

SyntaxError:JSON中位置1处的意外标记o

function address_transaction(address,callback)
{
var api_key='11111111111111'; 
var type='na';  
var url='some url';

var request = require('request');
request(url, function (error, response, body) {
  if (!error && response.statusCode == 200) {    
    var new1 =JSON.parse({"address":address,"response":response});
    callback(new1);  
  }
  else {
    console.log("Error "+response.statusCode)
  }
})
}

您不能解析
JSON.parse({“address”:address,“response”:response})

您必须首先字符串化您不能解析
JSON.parse({“address”:address,“response”:response})

您必须首先字符串化删除
JSON.parse

  if (!error && response.statusCode == 200) {    
    var new1 =JSON.parse({"address":address,"response":response});
    callback(new1);  
  }
您正在尝试将JSON转换为对象,但您已经有了一个对象,并且无法这样做

按以下方式发送您的数据:

var new1 = {"address":address,"response":response};

删除
JSON.parse

  if (!error && response.statusCode == 200) {    
    var new1 =JSON.parse({"address":address,"response":response});
    callback(new1);  
  }
您正在尝试将JSON转换为对象,但您已经有了一个对象,并且无法这样做

按以下方式发送您的数据:

var new1 = {"address":address,"response":response};
  • parse({“address”:address,“response”:response});是错误的,因为JSON.parse(…paramString)需要字符串作为参数,而不是代码中的对象
  • {“地址”:地址,“应答”:应答};已经是一个有效的JSON对象,因此您无需再执行任何操作
  • 删除JSON.parse应该可以解决您的问题:

    var new1 = {"address":address,"response":response};
    
    我建议你检查一下这些函数

  • parse({“address”:address,“response”:response});是错误的,因为JSON.parse(…paramString)需要字符串作为参数,而不是代码中的对象
  • {“地址”:地址,“应答”:应答};已经是一个有效的JSON对象,因此您无需再执行任何操作
  • 删除JSON.parse应该可以解决您的问题:

    var new1 = {"address":address,"response":response};
    

    我建议您检查一下函数,查看它

    在nodejs中,您需要知道的重要一点是第一个参数是错误,因此当您遇到错误时,需要像回调(err)一样处理它。如果您得到一个结果,那么像这样返回这个结果
    回调(null,result)


    在nodejs中,您需要知道的重要一点是,第一个参数是一个错误,所以当您遇到错误时,需要像回调(err)一样处理这个问题。如果您得到一个结果,那么像这样返回这个结果
    回调(null,result)


    尝试不使用JSON。parse
    它已经是JSON了,请不要使用parse方法。JSON.parse()用于将字符串转换为JSON objectTry,而不使用
    JSON.parse
    它已经是JSON了,请不要使用parse方法。parse()用于将字符串转换为JSON对象