以下のコードは、 JSON 多次元配列から動的に取得した要素を追加するときに得られる迷惑なundefinedを除いて、問題なく機能します。どこから来ているのかわかりませんでしたが、関数の外で変数を宣言し、それを内部で使用してデータを蓄積することから来ていると思います。$.each()
var c = 0;
var q = 1;
$.each(json, function (i, data) {
var answers; // declared here and outside this function - same results.
$.each(data.answers, function (i, a) {
answers += '<tags>' + a + '</tags>'; // the problem is here "maybe".
});
$('.foo').append(answers); // I get "undefined" ahead of values retrieved.
});