在aspx页foreach循环- CS1026:)预期
本文关键字:CS1026 预期 循环 aspx foreach | 更新日期: 2023-09-27 18:13:08
在下面的代码块中,我得到了编译器错误:CS1026:)预期在那一行:
"position": <%=node.Attribute("level").Value;%>,
完整代码:
<script type="application/ld+json">
{"@context": "http://schema.org",
"@type": "BreadcrumbList",
"itemListElement":
<% foreach (var node in firstLevelChildren) {%>
[{"@type": "ListItem",
"position": <%=node.Attribute("level").Value;%>,
"item":
{"@id": <%=node.Attribute("url").Value; %>,
"name": <%=node.Attribute("nav_title").Value; %>}},
]
<%}%>
}
</script>
我不明白出了什么问题,所有的括号似乎都正确关闭。谢谢您的帮助
从所有内联值中删除分号;
:
<% foreach (var node in firstLevelChildren) {%> [{
"@type": "ListItem",
"position": <%= node.Attribute("level").Value %>,
"item": {
"@id": <%= node.Attribute("url").Value %>,
"name": <%= node.Attribute("nav_title").Value %>
}
}, ]
<%}%>
还有,你的json
语法似乎不正确,最后一行,困扰我。你不应该得到一个编译错误,只是无效的json
}
}, ]
我想应该是
}
} ],
逗号应该在每个数组元素之后