Simple object serialization

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • wweems@gmail.com

    Simple object serialization

    I've got a simple javascript object that represents a small portion of
    a page.

    I'd like to "serialize" these objects into something I can then parse
    up with asp.net and c# on the other end.

    I've got the remote scripting portion all setup and it works great.

    My question is... if I have an object that looks like the following

    Card->Name
    ->Address
    ->Phone
    ->Notes

    How can I convert that to a simple string to send to a server. I could
    do it manually eg, write a Card.Serialize( ) method that simply wraps it
    in generic XML, but is there anyway I can do it automatically.. . that
    works in IE and FF?


    Thanks very much in advance!
    Weston

  • Alexis Nikichine

    #2
    Re: Simple object serialization

    wweems@gmail.co m wrote:
    [color=blue]
    > My question is... if I have an object that looks like the following
    >
    > Card->Name
    > ->Address
    > ->Phone
    > ->Notes
    >
    > How can I convert that to a simple string to send to a server. I could
    > do it manually eg, write a Card.Serialize( ) method that simply wraps it
    > in generic XML, but is there anyway I can do it automatically.. . that
    > works in IE and FF?[/color]

    If XML were not a strong requirement, I would suggest you to take a look
    at Douglas Crockford's http://www.json.org, and use its "stringify"
    (http://www.crockford.com/JSON/js.html )function as-is.

    Otherwise, I would take the time to understand it, and turn it into a
    genric, say 'xmlify', function, which should not be that hard. The
    resulting XML strings would then conform to a DTD defined mainly by the
    name of your object fields, so it will be up to the server side to adapt
    itself to understand the resulting XML.

    Related to your problem are the existences of

    * some nicely fleshed XML parsers fully written in javascript, such as

    * the XMLHttp object: http://jibbering.com/2002/4/httprequest.html
    * the possibility to embed XML "data island" in your document.

    Hope this helps,


    Alexis

    Comment

    Working...