0

In the following block of code, i got the compilator error : CS1026: ) expected at that line :

"position": <%=node.Attribute("level").Value;%>,

Full code:

<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>

I can't understand what's wrong, all the brackets seem to be correctly closed.. Thank you for your help

1
  • at the end of the last line ""name": <%=node.Attribute("nav_title").Value; %>}}," I see a comma. Maybe you have to check if there are multiple elements in your loop cicle and manage the comma.. Commented Oct 14, 2016 at 11:32

1 Answer 1

1

remove the semicolon ; from all inline values:

<% foreach (var node in firstLevelChildren) {%> [{
  "@type": "ListItem",
  "position": <%= node.Attribute("level").Value %>,
  "item": {
    "@id": <%= node.Attribute("url").Value %>,
    "name": <%= node.Attribute("nav_title").Value %>
  }
}, ]
<%}%>

also, you're json syntax seems to be incorrect, the line before last, troubles me. you should not get a compilation error though, just invalid json

instead of

   }
}, ]

i think it should be

   }
} ],

the comma should be after each array element

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.