döndürür JSON yapısında veya JS'de yanlış olan veya içindeki öğeleri nasıl ayıklayabildiğim?JavaScript Ayrıştırma JSON ben JSON ayrıştırmak çalışırken bir hata alıyorum sözdizimi hatası
DÜZENLEME (Jaromanda X'in ve CH Buckingham cevap göre):
$('#hdnAggregateAll').val(JSON.stringify(aggregateAll));
console.log(aggregateAll); $('#hdnAggregatePersonal').val(JSON.stringify(aggregatePersonal)); $('#hdnAggregateBusiness').val(JSON.stringify(aggregateBusiness)); $('#hdnMinistryAggregate').val(JSON.stringify(ministryAggregate));
$('#hdnCAAggregate').val(JSON.stringify(caAggregate));
$('#hdnSTaxAggregate').val(JSON.stringify(sTaxAggregate));
$('#hdnBTaxAggregate').val(JSON.stringify(bTaxAggregate));
$('#hdnLETaxAggregate').val(JSON.stringify(leTaxAggregate));
HATA: Bloğunda
if (item.processid !== "0")
:
function createFormLinks(formItems, index)
{
// create all links on the page and add them to the AtoZContent div for now
var parentContainer = $("#AtoZContentDiv");
if (parentContainer === null)
{
// if it doesn't exist, we exist cause I can't reliably add a new control to the body and get the display
// location correct
return;
}
// sort form link array first
formItems = sortResults(formItems, 'name', true);
var count = 0;
$.each(formItems, function(i, item)
{
var link;
count = count + 1;
//add links to parent container
if (item.processid !== "0")
{
link = item.formlink;
}
else if (item.pdflink !== "")
{
link = item.pdflink;
}
var container = $("#AtoZContent-" + index);
var itemType = "all";
if (item.type !== null && item.type !== undefined && item.type.length === 1) itemType = item.type[0];
var str = "<div id='divFormLink-" + index + "-" + count + "' type='" + itemType + "' ";
if (item.name !== undefined && item.name !== null)
{
str = str + " ministry='" + stripPunctuation(item.ministry) + "' ";
str = str + " ca='" + stripPunctuation(item.ca) + "' ";
// now, we need to handle these differently since they can have multiple values
str = str + " stax='";
for (i = 0; i < item.stax.length; i++)
{
str = str + stripPunctuation(item.stax[i]);
}
str = str + "' ";
str = str + " btax='";
for(i = 0; i < item.btax.length; i++)
{
str = str + stripPunctuation(item.btax[i]);
}
str = str + "' ";
str = str + " letax='";
for(i = 0; i < item.letax.length; i++)
{
str = str + stripPunctuation(item.letax[i]);
}
str = str + "' ";
}
str = str + " index='" + index + "' style='word-wrap: break-word;'></div>";
container.append(str);
var innerDiv = $("#divFormLink-" + index + "-" + count);
appendIcon(innerDiv, item.pubType);
innerDiv.append("<a id='formLink-" + index + "-" + count + "' href='" + link + "'>" + item.name + "</a>");
innerDiv.append("<div id='formDesc-" + index + "-" + count + "'>" + item.desc + "</div><br />");
});
}
satırda
10:42:24.274 TypeError: item is undefined
createFormLinks/<()eformsAtoZIndex.aspx:5644
.each()jquery-1.11.1.min.js:2
createFormLinks()eformsAtoZIndex.aspx:5638
processResult()eformsAtoZIndex.aspx:5507
m.Callbacks/j()jquery-1.11.1.min.js:2
m.Callbacks/k.fireWith()jquery-1.11.1.min.js:2
x()jquery-1.11.1.min.js:4
.send/b()jquery-1.11.1.min.js:4
1eformsAtoZIndex.aspx:5644:1
, eğer boş veya bir nesne sizin stringify işleve olmayan bir numarası ya da bir Boole veya Tarih, ya da bir şey, bu 'undefined' döndürür Bir dizge, ayrıştırmaya çalıştığınızda tam olarak bu hatayı verecektir. JSON dizgisi döndürmesi bekleniyorsa, dizgi işlevinizi neden karmaşıklaştırıyorsunuz? Sadece JSON.stringify kullanın ve onunla yapın –
Jaromanda X ile katılıyorum, özel stringify'ı kaldırın, JSON.stringify kullanın. Sorununuzun çözülüp çözülmediğine bakın. –
@CHBuckingham Bir tür hata alıyorum: 'TypeError: item undefined'. Yaptığım değişiklikler için güncellenmiş soruya bakın. – Brian