Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why I am getting array JSON response when I call method from Web API?

I am getting array which include my JSON when I call that method in postman like

 [
    {
        "spark_version": "7.6.x-scala2.12"
    }
]

API Method

[HttpGet]
    public IActionResult GetTest(int ActivityId)
    {
        string StoredJson = "exec sp_GetJobJSONTest " +
            "@ActivityId = " + ActivityId ;
        var result =  _context.Test.FromSqlRaw(StoredJson);
        return Ok(result);
    }

I want to get rid from square brackets [ ] in my response. How should I do that ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

for getting first row need to use .FirstOrDefault()

[HttpGet]
    public IActionResult GetTest(int ActivityId)
    {
        string StoredJson = "exec sp_GetJobJSONTest " +
            "@ActivityId = " + ActivityId ;
        var result =  _context.Test.FromSqlRaw(StoredJson).ToList().FirstOrDefault();
        return Ok(new {details = result };);
    }
 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading