如何解决错误ReferenceError:在nodejs coffeescript中没有定义json_decode

时间:2016-04-05 05:05:52

标签: node.js coffeescript

我想检索我喜欢的帖子。我已编写代码但显示错误。

    facebookDataUrl = "http://graph.facebook.com/yourstory.com/2016/04/shotpitch-startup-trended-product-hunt/"
    console.log facebookDataUrl     
    data = Http::curl(facebookDataUrl)
fbshares = json_decode(data, true)
fbsharescnt = fbshares['shares']
console.log fbsharescnt

以上代码显示错误

fbshares = json_decode(data, true);
         ^

ReferenceError:未定义json_decode

1 个答案:

答案 0 :(得分:1)

使用JSON.parse()

get = require 'http-get-shim'                                            

url = 'http://graph.facebook.com/yourstory.com/2016/04/shotpitch-startup-trended-product-hunt/'                                                   

get url, (er, resp, body) ->                                             
  data = JSON.parse body                                                 
  console.log data