c# - How do I convert an IEnumerable to JSON? -


i have method returns ienumberable containing 1..n records. how convert results json string?

thanks!

ienumerable<int> sequenceofints = new int[] { 1, 2, 3 }; ienumerable<foo> sequenceoffoos = new foo[] { new foo() { bar = "a" }, new foo() { bar = "b" } };  var serializer = new system.web.script.serialization.javascriptserializer(); string outputofints = serializer.serialize(sequenceofints); string outputoffoos = serializer.serialize(sequenceoffoos); 

which produces output

[1,2,3] [{"bar":"a"},{"bar":"b"}] 

and can sequence

ienumerable<foo> foos = serializer.deserialize<ienumerable<foo>>(outputoffoos); 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -