JSON => JavaScript type mismatch

Last post 09-20-2007 2:36 AM by sawbill. 2 replies.

Sort Posts:

  • JSON => JavaScript type mismatch

    09-18-2007, 3:01 AM
    • Loading...
    • sawbill
    • Joined on 03-16-2004, 12:00 AM
    • Posts 16

    I am trying to use AJAX with Virtual Earth. One issue I am having is with transfering objects from the server to the client. I have created C# object on the server that look like the Virtual Earth objects (VELatLong, VELatLongRectangle etc) and I can serialize them to JASON and deserialize them on the client (using Sys.Serialization.JavaScriptSerializer.deserialize)

    I can look at these objects in the debugger and they have the right properties, with the right values, but they are not the real object types. The Virtual Earth APIs validate parameters - e.g. if(VELatLongRectangle.prototype.isPrototypeOf(a)) - which my objects fail.

    So is there an easy way to deserialize to the correct object types? (Have I missed a deserialize function which takes a type hint) or do I have to write a series of converter functions e.g. :

        _2VELatLong:function(o)
        {
            if (o == null)
            {
                return null;
            }
            else
            {
                return new VELatLong(o.Latitude, o.Longitude);
            }
        }

    --

    David

    Filed under: ,
  • Re: JSON => JavaScript type mismatch

    09-19-2007, 3:29 PM
    • Loading...
    • dwhite
    • Joined on 02-08-2007, 9:25 AM
    • Bristol, CT
    • Posts 1,224

    Have you looked at the tutorials? This is part 3, but you can navigate back through them from here: http://virtualearth.spaces.live.com/blog/cns!2BBC66E99FDCDB98!536.entry

    Hope this helps you...

    -Damien

    ** Remember to mark posts as the answer to help future users. **

    Latest Blog Post:
    Fujitsu ScanSnap S510 Review
  • Re: JSON => JavaScript type mismatch

    09-20-2007, 2:36 AM
    • Loading...
    • sawbill
    • Joined on 03-16-2004, 12:00 AM
    • Posts 16

    I have looked at this tutorial, but, alas, the links (to the demo and source) dont work for me.

    However, it says "I am responding with Javascript that will be executed in the browser". This is not my case. I am responding with an object graph serialized using JSON which I would like to deserialize as specific object types. I could hand craft code on the server to concaternate strings to write a script to create the right objects, but I thought using JSON should make life easier.

Page 1 of 1 (3 items)
Microsoft Communities
Page view counter