HI,
I have a WS that returns a complex type let's call itJSONResultWrapper-one of the properties ofJSONResultWrappersay,Result, is an Array of another complex type say,JSONResult.
When this serializes down the wire, it looks like it has serialized correctly, but when it is deserialized back into an object at the client, instead ofResult being an Array orJSONResult,it is an object.
Sure, I can iterate through this and add each element into my array - but should I have to ?
c# code
public class JSONResultWrapper
{
...other props here...
public JSONResult[] Results;
...
}
--8<-----8<-------
[WebMethod]
public JSONResultWrapper GetResults(string SearchKey, string type)
{
JSONResultWrapper Jrw = new JSONResultWrapper();
.....
return Jrw;
}
--8<-----8<-------
JSON (from firebug)
{"AccommodationType":["Hotel","Apartment"],"Allocation":["Named"],"Results":[{"id":"694999631","ds":28,"dp":74,"tn" :4034,"b":3,"c":280460,"s":0,"u":0,"dd":0,"at":0,"al":0,"du":6,"ap":2,"cp":0,"r":"3*","p":"74","ip":1
,"an":"Tophotels Casino Royal","q":"s17056","dl":null,"e":1,"mo":0},{"id":"692909484","ds":28,"dp":74
,"tn":388,"b":2,"c":1701,"s":0,"u":1,"dd":1,"at":1,"al":0,"du":7,"ap":2,"cp":0,"r":"","p":"88","ip":1
,"an":"","q":"6HR1357","dl":"","e":1,"mo":0}]}
Javascript.
--8<-----8<-------
TT.ResultCollection = function(InitValues) {
TT.ResultCollection.initializeBase(this);
......
this.Results = new Array();
.....
}
--8<-----8<-------
_onMethodComplete : function(result, userContext, methodName) {
try{
this.Results = $create(TT.ResultCollection,result);
}
--8<-----8<-------
I end up with this.Results.Results being an Object with properties, rather than an Array.
So far I have tried all sorts of types for Results ion the server but I realised that they were all serializing OK - it is the deserializing that is causing me problems.
What gives?
Cheers, all.
Have a look at http://www.microsoft.com/belux/msdn/nl/community/columns/jdruyts/wsproxy.mspx
You may need to use Jelle Druyts WSDL import modifier to fix the issue/
alternatively, have a look at the ajax-extensions converter class: http://ajax.asp.net/docs/mref/T_System_Web_Script_Serialization_JavaScriptConverter.aspx
No comments:
Post a Comment