0

I have this code..

 Models.Person p = new testmvc.Models.Person { Firstname = "yongeks", Lastname = "ucab" };
 Models.Person p2 = new testmvc.Models.Person { Firstname = "lyn", Lastname = "torreon" };
 string q = JavaScriptConvert.SerializeObject(new String[] { JavaScriptConvert.SerializeObject(p), JavaScriptConvert.SerializeObject(p2) });
 Console.WriteLine(q);
 return q;

i need to parse this code into jquery.. using json request.. can somebody help me..

John Sheehan
78.3k30 gold badges162 silver badges194 bronze badges
asked Dec 21, 2008 at 23:57

2 Answers 2

8

Just use the controller's Json method to serialize the type and return a JsonResult:

Models.Person p2 = new testmvc.Models.Person { Firstname = "lyn", Lastname = "torreon" };
return Json( p2 );
answered Dec 22, 2008 at 0:14

Comments

4

I like working with the Newtonsoft json library. it allows you greater control over the json serialization process so you can specify what to do with null values etc

e.g

 JsonNetResult jsonNetResult = new JsonNetResult();
 jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
 jsonNetResult.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
 jsonNetResult.Data = nodes
 return jsonNetResult; 
answered Dec 22, 2008 at 13:32

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.