gpt4 book ai didi

javascript - 如何在敏锐的js中读取简单的json文件

转载 作者:行者123 更新时间:2023-12-03 08:47:25 25 4
gpt4 key购买 nike

我有几个基本的本地 json 文件。我想使用 eager.io 可视化 json 数据。但不知怎的,我无法将我的事件发送给敏锐。控制台中没有错误。

var client = new Keen({
projectId: "key",
writeKey: "key"
});



var data = $.getJSON( "data/web_stories.json", function( data ) {
var storyData = data
Keen.ready(function(){
var multipleEvents = {
"stories": data
};
// Send multiple events to several collections
client.addEvents(multipleEvents, function(err, res){
if (err) {
console.log('there is an error!')
}
else {
console.log('data sent')
}

数据看起来像这样

[
{ link: "www.link.com",
heading: 'here is the heading',
image: "www.image.com" },
{ link: "www.link.com",
heading: 'here is the heading',
image: "www.image.com" }

]

最佳答案

我看到 data 被定义了几次。这个怎么样:

var client = new Keen({
projectId: "key",
writeKey: "key"
});

Keen.ready(function(){
$.getJSON( "data/web_stories.json", function( data ) {
// Send multiple events to several collections
client.addEvents({ 'stories': data }, function(err, res){
if (err) {
console.log('there is an error!')
}
else {
console.log('data sent')
}
});
});
});

关于javascript - 如何在敏锐的js中读取简单的json文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32823885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com