0

みなさん、おはよう、

文字列を反復処理して でデータを解析し、$.parseJSONそれを select に送信しようとしていますが、何らかの理由で、開始時にfor何も起こらず、エラーなども発生しません..単純に、スクリプトが動作を停止します (終了、php)

json:

{
"response": {
    "chars": {
        "0": {
            "guid": "728166",
            "name": "Pepito",
            "race": "1",
            "class": "6",
            "gender": "0",
            "level": "80",
            "money": "1412915382",
            "apoints": "0",
            "hpoints": "200000",
            "tkills": "1731",
            "title": "0"
        },
        "1": {
            "guid": "778879",
            "name": "Chocolate",
            "race": "7",
            "class": "8",
            "gender": "1",
            "level": "88",
            "money": "0",
            "apoints": "0",
            "hpoints": "0",
            "tkills": "0",
            "title": "0"
        }
    }
}

}

コード:

var json = *this is the top json*;    
var parsed = $.parseJSON(json);
for (var i=0; i<parsed.length; i++){
    console.log(parsed.response.chars[i].name);
}

どの部分が間違っていますか?私の知る限り、私には何の過失もありません。

ありがとう!

4

2 に答える 2

0

試す:

var json = *this is the top json*;    
var parsed = $.parseJSON(json);
for (var i = 0; i < parsed.response.chars.length; i++){
    console.log(parsed.response.chars[i].name);
}
于 2013-03-23T14:21:36.907 に答える
0

配列ではなくオブジェクトを反復処理しています!

var json = *this is the top json*;    
var parsed = $.parseJSON(json);
for (var key in parsed.response.chars){
    console.log(key);
    console.log(parsed.response.chars[key].name);
}
于 2013-03-23T14:21:52.780 に答える