I am creating a new .Net API(using .net core) and trying to return JSON data in multiline. e.g.
[{"ID":"1"},{"ID":"2"},{"ID":"3"}]
//Current Output
**The expected output should be like.
[{"ID":"1"},
{"ID":"2"},
{"ID":"3"}]
Below is my web api code and my return type is Object.
var Response = await idc.GetActualData(clientID, tempId, dt, data);//DB call
responseStr = JsonConvert.SerializeObject(Response);
return responseStr;
CodePudding user response:
try this
return JsonConvert.SerializeObject(Response).Replace("},","},\n").
output
[{"ID":"1"},
{"ID":"2"},
{"ID":"3"}]
or you can like this too
return JsonConvert.SerializeObject(Response, Newtonsoft.Json.Formatting.Indented);