Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 07, 2012 03:25 PM by sean freeman
Member
170 Points
96 Posts
May 07, 2012 03:23 PM|LINK
hi,
here is the c#object sent back to browser using json method.
public class vm
{
public IEnnumerable<posts> p{get;set;}
public IEnnumerable<nav> n{get;set;}
}
and the following controller gets data from database and sends back to browser.
public ActionResult getcontent(menu m) { vm vms = new vm(); vms.n=db.navimenus.Where(r=>r.menuname==m.name).ToList(); string s = vms.n.FirstOrDefault().navname; vms.p = db.posts.Where(r => r.navname == s).ToList(); return Json(vms) ; }
when browser recieves this json object.
browser gives an error :unexpected token "o";
browser is recieving that object. i can see the elements in it in FIRE BUG.
but when i try to execute this "JSON.parse(response)";
where response is the json object sent to browser, it gives me an error object with messege. "Unexpected token '0'";
can anyone help me with this? :D
May 07, 2012 03:25 PM|LINK
this is the response object i get from server:
Object n: Array[2] 0: Object date: "/Date(1355250600000)/" demos: null menuname: "one" navname: "one" notes: null posts: Array[3] __proto__: Object 1: Object date: "/Date(1355250600000)/" demos: null menuname: "one" navname: "three" notes: null posts: null __proto__: Object length: 2 __proto__: Array[0] p: Array[3] 0: Object comments: null date: "/Date(1355250600000)/" id: 1 name: "first post for ya" navname: "one" __proto__: Object 1: Object comments: null date: "/Date(1355250600000)/" id: 2 name: "you know something" navname: "one" __proto__: Object 2: Object comments: null date: "/Date(1355250600000)/" id: 3 name: "i you" navname: "one" __proto__: Object length: 3 __proto__: Array[0] __proto__: Object
sean freeman
Member
170 Points
96 Posts
Unable to parse a json object
May 07, 2012 03:23 PM|LINK
hi,
here is the c#object sent back to browser using json method.
public class vm
{
public IEnnumerable<posts> p{get;set;}
public IEnnumerable<nav> n{get;set;}
}
and the following controller gets data from database and sends back to browser.
public ActionResult getcontent(menu m) { vm vms = new vm(); vms.n=db.navimenus.Where(r=>r.menuname==m.name).ToList(); string s = vms.n.FirstOrDefault().navname; vms.p = db.posts.Where(r => r.navname == s).ToList(); return Json(vms) ; }when browser recieves this json object.
browser gives an error :unexpected token "o";
browser is recieving that object. i can see the elements in it in FIRE BUG.
but when i try to execute this "JSON.parse(response)";
where response is the json object sent to browser, it gives me an error object with messege. "Unexpected token '0'";
can anyone help me with this? :D
sean freeman
Member
170 Points
96 Posts
Re: Unable to parse a json object
May 07, 2012 03:25 PM|LINK
this is the response object i get from server: