I have a JSON data
[
{
"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! ;) "
]
}
]
I am parsing it using jQuery and iterating it like this;
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";
}
I’m not too sure if iterating this in a for loop is a good idea. Could anyone please suggest me a better/optimized way to iterate the parsed json value?
The way you’re doing it just now is the most efficient way to do it, except:
Could also be written better as :