I have an app. It's frontend is set on Angular 6 using typescript controllers and it's backend on a C# api.
I try to send json from C# controller as response but typescript controller cannot read it successfully.
C# code:
[HttpGet]
[Route("getAll")]
public string GetAllUserStories()
{
.
.
.
string json = JsonConvert.SerializeObject(storiesList);
json = "\"" + json + "\"";
return json;
}
Story class :
public class Story
{
/// <summary>
/// The story short description.
/// </summary>
public string description { get; set; }
/// <summary>
/// The story id.
/// </summary>
public int Id { get; set; }
/// <summary>
/// The list of places this story contains.
/// </summary>
public string place { get; set; }
/// <summary>
/// The list of friends travelled with on this story.
/// </summary>
public string friends { get; set; }
/// <summary>
/// The story's photo.
/// </summary>
public Photo Photo { get; set; }
/// <summary>
/// The day this story started.
/// </summary>
public string date { get; set; }
/// <summary>
/// The day this story ended.
/// </summary>
public DateTime EndingDate { get; set; }
/// <summary>
/// The amount of money wasted on this story.
/// </summary>
public string cost { get; set; }
/// <summary>
/// How much the user liked this story.
/// </summary>
public string rating { get; set; }
/// <summary>
/// A short comment at the end of the story.
/// </summary>
public string Conclusion { get; set; }
/// <summary>
/// Story image.
/// </summary>
public string image { get; set; }
}
Typescript controller:
const stories =
this.http.get("https://localhost:44341/stories/getAll").subscribe(results => {this.retGetData= results as AllStories;});
And I receive on console on browser : SyntaxError: Unexpected token d in JSON at position 4 text: ""[{"description":"test description","Id":10,"place":"test place","friends" ....etc
How can I cast a list of objects to Json so it would be readable from Angular??