0
[{"tag":35,"value":"W","children":[
    {"tag":55,"value":"GOOG","children":null},
    {"tag":262,"value":"ghost332002m0","children":null},
    {"tag":268,"value":"1","children":[
       {"tag":269,"value":"B","children":null},
       {"tag":271,"value":"0","children":null},
       {"tag":336,"value":"3","children":null}
     ]}
  ]},
   {"tag":35,"value":"W","children":[
       {"tag":55,"value":"GOOG","children":null},
       {"tag":262,"value":"ghost332002m0","children":null},
       {"tag":268,"value":"0","children":null}
   ]} 
]

JSONがあり、それはFIX Market Dataであり、これらのネストされたグループがあるので、これはJSONでのこれらのFIXメッセージの私の表現です。とにかく、私はそれを私のWebクライアントに送信し、ディスプレイに戻す必要があります。

$.getJSON('/receive', function(data, returnValue) {
    $.each(data, function(index,value) {
        $('#output').append('<p>');
        appendStuff(value);
        $('#output').append('</p>');
    });
function appendStuff(children) {
    debug_var.push(children);
    $.each(children, function(child) {
        $('#output').append(child.tag+'='+child.value+' ');
        if (child.children != null) {
            appendStuff(child.children);
        }
    })
}

私は再帰を使用してこのデータをスピンし、すべてを印刷しようとしています。私が得るものは:

undefined=undefined undefined=undefined undefined=undefined

私は何が間違っているのですか?

ああ、データはすべてdebug_varにあります...

ここに画像の説明を入力してください

4

1 に答える 1

3

あなたはおそらくもっと近いものを望んでいます

$.getJSON('/receive', function (data) {
    $.each(data, function(index,value) {
        $('#output').append('<p>');
        appendStuff(value.children || []);
        $('#output').append('</p>');
    });
    function appendStuff(children) {
        $.each(children, function(i, child) {
            $('#output').append(child.tag+'='+child.value+' ');
            if (child.children != null) {
                appendStuff(child.children);
            }
        });
    }
});

上記は親のタグを出力しないことに注意してください。追加することをお勧めします。

于 2013-03-13T05:19:38.987 に答える