Tuesday, 27 August 2013

adding json object name in asp.net web api

adding json object name in asp.net web api

created an web api that outputs json, trying to use it with backbone.js
pagination plugin to ouput the results to the backbone.js infinite-paging
plugin
this is my outputed json
[{"id":1,"title":"test1""desc":"book1"},
{"id":2,"title":"test2","desc":"book2"},
{"id":3,"title":"test3", "desc":"book3"},
{"id":4,"title":"test4","desc":"book4"},
{"id":5,"title":"test5","desc":"book5"},
{"id":6,"title":"test6","desc":"book6"}]
but i need to have the name of object included as the backbone.js
paginator requires to return the response object. think im almost there
but cant seem to get it to show or work out how i add the object name to
it ?
{"object name:"[{"id":1,"title":"test1","desc":"book1"},
{"id":2,"title":"test2","desc":"book2"},
{"id":3,"title":"test3","desc":"book3"},
{"id":4,"title":"test4","desc":"book4"},
{"id":5,"title":"test5","desc":"book5"},
{"id":6,"title":"test6","desc":"book6"}]}
public class latestnewsController : EntitySetController<news, int>
{
onlinepressEntities _context = new onlinepressEntities();
latestnewsController()
{
_context.Configuration.LazyLoadingEnabled = false;
}
[Queryable]
public override IQueryable<news> Get()
{
return _context.news;
}
protected override news GetEntityByKey(int key)
{
return _context.news.FirstOrDefault(c => c.ID == key);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_context.Dispose();
}
}

No comments:

Post a Comment