-1

C# Webservice is generating this json

[{\"Question\":\"This is the Question no 0\",\"Answer1\":\"This is Answer1 of Question 0\",\"Answer2\":\"This is Answer2 of Question 0\",\"Answer3\":\"This is Answer3 of Question 0\",\"Answer4\":\"This is Answer4 of Question 0\",\"Correct\":1},{\"Question\":\"This is the Question no 1\",\"Answer1\":\"This is Answer1 of Question 1\",\"Answer2\":\"This is Answer2 of Question 1\",\"Answer3\":\"This is Answer3 of Question 1\",\"Answer4\":\"This is Answer4 of Question 1\",\"Correct\":1},{\"Question\":\"This is the Question no 2\",\"Answer1\":\"This is Answer1 of Question 2\",\"Answer2\":\"This is Answer2 of Question 2\",\"Answer3\":\"This is Answer3 of Question 2\",\"Answer4\":\"This is Answer4 of Question 2\",\"Correct\":1}]

but online json validator is showing errors in the json string. Angular also not parsing the json string correctly and giving error. I am using Newtonsoft json serialize to generate json string. Please help.

Hasan Zubairi
  • 1,037
  • 4
  • 23
  • 57

1 Answers1

0

Looks like you double encoded the object to JSON in your .net code. First you encode an object to JSON and get a string.

console.log(
  "normal encoded:",
  JSON.stringify({hello:"world"})
);
console.log(
  "double encoded:",
  JSON.stringify(JSON.stringify({hello:"world"}))
);

Problem is likely not in ES but in your .net code. The solution to your problem is likely here.

HMR
  • 37,593
  • 24
  • 91
  • 160