jquery each and a JSON string
Ok I think I am having a bad moment. Usually I can iterate over JSON without issue.
Here is a Sample String
{
"service 1": {
"admin": {},
"list": [
"1"
],
"info": [
{
"id": "1",
"details": "Failed",
"curr-status": "Warning",
"curr-status-class": "warning"
}
],
"status": [
{}
]
},
"service 2": {
"admin": {},
"list": [
"1"
],
"info": [
{
"id": "1",
"details": "Failed",
"curr-status": "Warning",
"curr-status-class": "warning"
}
],
"status": [
{}
]
}
}
What I am trying to do is be able to do an $.each() on every service then make a pretty list out of it, and eventually sort based on etc..
My last failed attempt at iterating through it is:
$('.refreshAllb').click(function()
{
$.post('services.json', {"x":"blank"}, function(data)
{
$('body').html('开发者_StackOverflow');
$.each(data, function(i)
{
$.each(data[i], function(x, z)
{
$('body').append(x.z+"<br>");
});
});
}, "json");
});
I have looped over various concepts of running each() with an each() to being a lone each. All I keep returning is object object or undefined. So I know I am in the ballpark but I am not hitting the nail on the head.. ideas?
$('.refreshAllb').click(function() {
$.post('services.json', {"x":"blank"}, function(data) {
$('body').empty();
$.each(data, function(serviceName) {
$.each(this, function(key) {
$('body').append(serviceName + "." + key + "=" + this + "<br/>");
});
});
}, "json");
});
精彩评论