• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Encoding javascript object to JSON

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey fellow ranchers,

I have a JavaScript object that I'd like to encode into JSON for Ajax transmission.

Does anyone know a JS framework that has a function that will translate a JSObject to JSON and back?

Pseudo-example:

[ October 13, 2006: Message edited by: Joel Bushart ]
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Usually JSON is generated on the server to be sent to the client. How are you planning on using with Ajax from the client?
 
Joel Bushart
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically I've got a Google maps marker that I want to be able to assign contents provided by the server for it's infowindow, but only when a user clicks on it.

So, I have the marker created and I want to send that marker object to the server. Then send it back so I can assign the info window data to the current marker object.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you need to send the data to the server as JSON? (Reason I ask is that I know of a few serve-side libraries to do this, but not client-side).

On the other hand, it shouldn't be all that hard to code one up...
 
Joel Bushart
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
So you need to send the data to the server as JSON? (Reason I ask is that I know of a few serve-side libraries to do this, but not client-side).

On the other hand, it shouldn't be all that hard to code one up...



yep, though I was hopeing someone had already done one I could "borrow"
 
Joel Bushart
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After a couple of attempts, a better solution turned out to be wrapping the object in another wrapper object to preserve it and use object methods in the wrapper to handle the ajax operations.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you looked at JSON.ORG

Eric
 
Joel Bushart
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, it helped a lot on the implementation specifics.

However, I found it leads to memory leaks, as I have an object being created by a third party that I was intending to transmit as JSON then update it with some info received via Ajax.

The update part just seems to add another object and won't match up in memory correctly.

However, using a wrapper allows me to save the memory pointer properly so that I am assured of addressing the same object, also reduces network overhead as I only need to send relevant parts of the data object instead of all of it.
reply
    Bookmark Topic Watch Topic
  • New Topic