将代码鸟回复解析为数组(或将 json 文本解析为代码鸟的回复)

Parse codebird reply into a array (or acces to the json text into the codebird's reply)

本文关键字:回复 代码 文本 json 数组 或将      更新时间:2023-09-26

我正在尝试使用codebird从Twitter获取一些数据。我有一个JavaScript脚本。我的问题是codebird的回复是一个对象而不是JSON。所以我不能使用 eval() 来解析数组中的 json 文本。我只需要访问 json 数据。

提前谢谢你

var cb = new Codebird();
cb.setConsumerKey("", "");
cb.setToken('','');  
cb.__call(
    "search_tweets",
    "q=Twitter",
     function (reply) {
    data = eval(reply) //parse the returned JSON to array
    }
}
);

如果需要将 JavaScript 对象转换为 JSON 字符串,可以使用

data = JSON.stringify(reply)

但通常最好处理对象本身 - 例如,您可以迭代它的属性(如果需要,可以创建自己的数组)