0

I am using the Values controller in Net Core VS 2019 to send JSON data back instead of string. This is the syntax I am using that is not accurate:

[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
    // GET api/values
    [HttpGet]
    public JsonResult Get()
    {
        return new JsonResult({
            "heroesUrl": "api/heroes",
            "textfile": "assets/textfile.txt"
        });
    }
}

I get red squiggly lines indicating a syntax error on the JSON objecs in the {}.

0

1 Answer 1

4

Use an anonymous object instead.

[HttpGet]
public IActionResult Get() {
    return new JsonResult( new {
        heroesUrl = "api/heroes",
        textfile = "assets/textfile.txt"
    });
}
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.