我从php
跟踪json{"status":{"message":"success","undeleted":[],"code":200}}
{"status":{"message":"success","undeleted":[{"id":7844118,"error":"This Document already Published"}],"code":200}}
我只是想检查未删除的'在jquery中是空的。如果不是空的,我需要从未删除的内容中取出每个ID及其错误消息。我不知道如何执行此操作。我将一次只获取一个
考虑这样的事情
var result = jQuery.parseJSON(data);
$.each(result.data, function(index, value) {
});
我做过类似的事,但得不到想要的答案
var result = jQuery.parseJSON(data);
$.each(result.status, function(index, value) {
alert(value);
});
答案 0 :(得分:1)
以下是如何操作:
http://jsfiddle.net/2zLby4r8/3/
var result = jQuery.parseJSON('{"status":{"message":"success","undeleted":[{"id":7844118,"error":"This Document already Published"},{"id":999999,"error":"New Errr"}],"code":200}}');
if (result.status.undeleted.length > 0) {
$.each(result.status.undeleted, function(index, value) {
alert("ID: " + value.id);
alert("Error: " + value.error);
});
} else {
alert("blank");
}