c# - How can I serialize my data using Json.net? -


i want convert data json. aslo want use json.net, working on asp.net mvc. have followed 2 links error during serialization using json javascriptserializer. , fastest json serializer .net released, not able yet it. have action calls method of class. method must return json. first of how serialize data , type of return should be. code snippet action first json class , method.

most importantly don't want json string because want able access fields in using "."

public actionresult highchartaction(int id) {    jsonmodel j = new jsonmodel();    ??? chartdata = j.getmessagesforchart(id); // should type of chartdata json data } ----------------------     public class jsonmodel {     public jsonresult getmessagesforchart(int id)     {           datarepository _messagerepository = new datarepository();           var gluc = _messagerepository.getallmessages(id);           var json = jsonconvert.serializeobject(gluc); // string           return json; // error because want jsonresult not string      } }  ---------------------     namespace monitorui.models     {         public class database         {             public int id { get; set; }              public datetime date_time { get; set; }              public int my_value{ get; set; }         }     } 

so var gluc of type ienumerable(database)


related continuing question here: how fill database list in series , xaxis objects of highchart

help please

your function :

public jsonresult getmessagesforchart(int id) {       datarepository _messagerepository = new datarepository();       var gluc = _messagerepository.getallmessages(id);       var json = jsonconvert.serializeobject(gluc); // string       return json; // error because want jsonresult not string  } 

update function :

public jsonresult getmessagesforchart(int id) {       datarepository _messagerepository = new datarepository();       database gluc = _messagerepository.getallmessages(id);       return jsonconvert.serializeobject(gluc);  } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -