SOE request parameter parsing: how to deserialize an array of customized object? (C#)

846
1
Jump to solution
05-17-2013 11:59 AM
SimonLeo
New Contributor III
for example, if the parameter TestArray looks like this:
[{     Id: 1,     Name: "hello" }, {     Id: 2,     Name: "world" }]


I have a class Test defined in the code:
public Class Test {     public int Id { get; set;}     public string Name { get; set; } }


then in SOE handler, how can deserialize TestArray to an array of Test objects?
If using:
object[] testArray; bool found = operationInput.TryGetArray("TestArray", out testArray);


then how can convert testArray from object[] to Test[] or IList<Test>?

thanks for any advice!
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
nicogis
MVP Frequent Contributor
you can write kind:

            object[] testArray;             bool found = operationInput.TryGetArray("parm1", out testArray); //testArray is a array object(JsonObject)              JavaScriptSerializer json_serializer = new JavaScriptSerializer();             Test myClass = json_serializer.Deserialize<Test>((testArray[0] as JsonObject).ToJson()); 

View solution in original post

0 Kudos
1 Reply
nicogis
MVP Frequent Contributor
you can write kind:

            object[] testArray;             bool found = operationInput.TryGetArray("parm1", out testArray); //testArray is a array object(JsonObject)              JavaScriptSerializer json_serializer = new JavaScriptSerializer();             Test myClass = json_serializer.Deserialize<Test>((testArray[0] as JsonObject).ToJson()); 
0 Kudos