1

実際には、jQuery モバイルを介して json 配列を解析したいのですが、あまり検索されずに立ち往生している場合は、助けてください。

私のjsonのフォーマット

{
"messagedetails":
    [{
    "msgData":"DEAR MEMBER\\\"S TODAY\\\"S KITTY WINNER IS N0 55.HOPE YOU ALL ENJOYED THE EVENING. THANK YOU\r\n MAHAVIRD (PLEASE KEEP SLIPS CAREFULLY)",
    "requestNosSms":64,
    "requestUserid":"16459",
    "spamReason":
    {
        "userApprove":"0",
        "senderApprove":"0",
        "templateMatch":80,
        "templateId":"6586",
        "spamKeywords":["winner"],
        "maxNosLimit":"0"
    },
    "id":"5124c1c446923e6c4100005f",
    "userName":"MAHAVIR DIAMOND",
    "date":"2013-02-20 17:59:57"
    },

     {
    "msgData":"DEAR MEMBER\\\"S TODAY\\\"S KITTY WINNER IS N0 55.HOPE YOU ALL ENJOYED THE EVENING. THANK YOU\r\n MAHAVIRD (PLEASE KEEP SLIPS CAREFULLY)",
    "requestNosSms":64,
    "requestUserid":"16459",
    "spamReason":
    {
        "userApprove":"0",
        "senderApprove":"0",
        "templateMatch":80,
        "templateId":"6586",
        "spamKeywords":["winner"],
        "maxNosLimit":"0"
    },
    "id":"5124c1c446923e6c4100005f",
    "userName":"MAHAVIR DIAMOND",
    "date":"2013-02-20 17:59:57"
    }]
}

そして、私はこれらのようなコードを使用しています

var test =null;                                     
                                        $.each(data, function(i,messages) {
                                            test = test + "<h1>"+messages][2]+"</h1>";

});

$("#results").html(test);
4

2 に答える 2

1

json では quote "を値に使用できません。値をエンコードする必要があります

入力

 array('<foo>',"'bar'",'"baz"','&blong&', "\xc3\xa9");

ある種のエンコードによる出力

 Normal: ["<foo>","'bar'","\"baz\"","&blong&","\u00e9"]
Tags: ["\u003Cfoo\u003E","'bar'","\"baz\"","&blong&","\u00e9"]
Apos: ["<foo>","\u0027bar\u0027","\"baz\"","&blong&","\u00e9"]
Quot: ["<foo>","'bar'","\u0022baz\u0022","&blong&","\u00e9"]
Amp: ["<foo>","'bar'","\"baz\"","\u0026blong\u0026","\u00e9"]
Unicode: ["<foo>","'bar'","\"baz\"","&blong&","é"]
All: ["\u003Cfoo\u003E","\u0027bar\u0027","\u0022baz\u0022","\u0026blong\u0026","é"]
于 2013-02-20T13:03:05.920 に答える
0

JSONは有効です。

次のコードを使用してみてください。

var test =null;                                     
$.each(data.messagedetails, function(i,messages) {
test = test + "<h1>" + messages.msgData +"</h1>";
});
$("#results").html(test);
于 2013-02-20T15:15:25.827 に答える