Setting Root element

Sep 2, 2008 at 4:20 PM
Hi
I'm developing a web app using Json.Net 3.0. I noticed that when I serialize an object using JavaScriptConvert.SerializeObject there's no way to set the root property of the object. Precisely, if I serialize the object "Person", I get something like

{\"Id\":1,\"Name\":\"Donald Duck\"}

Is there an easy  way to set the root property of the elements, in order to set the root of the serialized object and get something similar to this

{"root": "friends" , "child":[{\"Id\":1,\"Name\":\"Donald Duck\"},{\"Id\":2,\"Name\":\"Mickey Mouse\"}]...

This would be very useful if I want to serialize different type of objects in the same string and then divide and parse accordingly the different objects.

Thanks in advance
Coordinator
Sep 4, 2008 at 4:31 AM
You could create a parent class and add the Person objects to it in a Child collection and serialize that.