【发布时间】:2015-05-08 00:48:27
【问题描述】:
我正在使用 jqCloud 插件来生成词云。此脚本依赖于以特定模式格式化的 json。我正在尝试将var msg 解析为json,就像在var word_array 中一样
$(function() {
var count = 3;
$.wordStats.computeTopWords(count, $('body'));
var msg = 'Top words:\n';
for (var i = 0, j = $.wordStats.topWords.length; i < j && i <= count; i++) {
msg += '\n' + $.wordStats.topWords[i].substring(1) + ': ' + $.wordStats.topWeights[i];
}
console.log(msg);
//this is what gets printed in the console
//Top words:
//bag: 46
//tote: 30
//ugh: 30
$.wordStats.clear();
// I am trying to get var msg to spit out json
// that is formatted like this
var word_array = [{
text: "Lorem",
weight: 15
}, {
text: "Ipsum",
weight: 9,
link: "http://jquery.com/"
}, {
text: "Dolor",
weight: 6,
html: {
title: "I can haz any html attribute"
}
}
// ...as many words as you want
];
$('#example').jQCloud(word_array);
【问题讨论】:
标签: javascript jquery json parsing