我有一个 JSON 数据
[
{
"Name": "Tom",
"Email": "tom@gmail.com",
"Notes": "Yea, it's good",
"Ratings": "5",
"Messages": [
"Tom - I am good",
"System - How're you doing?",
"Tom - True, that!",
"System - Oh Yes! ;) "
]
},
{
"Name": "Sunny",
"Email": "sunny@gmail.com",
"Notes": "Yea, it's good",
"Ratings": "2",
"Messages": [
"Sunny-I am good",
"System - How're you doing?",
"Sunny - True, that!",
"System - Oh Yes! ;) "
]
}
]
我正在使用 jQuery 解析它并像这样迭代它;
var jsonData = $("#jsonData").val();
var plainData = $.parseJSON(jsonData);
for (var j = 0; j < plainData.length; j++) {
var Name = plainData[j].Name;
var Email = plainData[j].Email;
var Notes = plainData[j].Notes;
var Ratings = plainData[j].Ratings;
var Messages = plainData[j].Messages;
var _messages = " ";
for (var i = 0; i < Messages.length; i++)
_messages += Messages[i] + "\n";
}
我不太确定在 for 循环中迭代它是否是一个好主意。谁能建议我一种更好/优化的方法来迭代解析的 json 值?