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

Time:03-21

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 ?

CodePudding user response:

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 };);
    }
 
  • Related