All I want to do is return a JSON to the browser.
This is what gets returned right now -- it's the JSON but it's inside a string. How do I return just a JSON?
And here's my code:
namespace ...Controllers
{
public class NotificationsController : ApiController
{
public string getNotifications(int id)
{
var bo = new HomeBO();
var list = bo.GetNotificationsForUser(id);
var notificationTreeNodes = (from GBLNotifications n in list
where n.NotificationCount != 0
select new NotificationTreeNode(n)).ToList();
List<Node> lOfNodes = new List<Node>();
foreach (var notificationTreeNode in notificationTreeNodes)
{
Node nd = new Node();
nd.notificationType = notificationTreeNode.NotificationNode.NotificationType + " " + "(" + notificationTreeNode.NotificationNode.NotificationCount + ")";
var notificationList = bo.GetNotificationsForUser(id, notificationTreeNode.NotificationNode.NotificationTypeId).Cast<GBLNotifications>().ToList();
List<string> notificationDescriptions = new List<string>();
foreach (var item in notificationList)
{
notificationDescriptions.Add(item.NotificationDescription);
}
nd.notifications = notificationDescriptions;
lOfNodes.Add(nd);
}
var oSerializer = new JavaScriptSerializer();
string sJSON = oSerializer.Serialize(lOfNodes);
return sJSON;
}
}
public class Node
{
public string notificationType
{
get;
set;
}
public List<string> notifications
{
get;
set;
}
}
}
If I try to do a GET with the URL for this controller, Fiddler is not showing anything under JSON.
Anyone know what the issue is here?