1) The Object.toJSON function should serve your purpose. http://api.prototypejs.org/language/object.html#tojson-class_method e.g. >> var cat = {name: 'Frisky', age: 2, favoriteQuotes: ['Meow', 'Purr'], likes: >> {'food': 'Tuna'}} >> Object.toJSON(cat) "{"name": "Frisky", "age": 2, "favoriteQuotes": ["Meow", "Purr"], "likes": {"food": "Tuna"}}"
2) If the only reason you're using JSON-Lib is for this specific purpose, may I suggest using json-simple (http://code.google.com/p/ json-simple/). Its small and functional. String catJSON = "{\"name\": \"Frisky\", \"age\": 2, \"favoriteQuotes \": [\"Meow\", \"Purr\"], \"likes\": {\"food\": \"Tuna\"}}"; JSONObject cat = (JSONObject)JSONValue.parse(catJSON); String name = (String)cat.get("name"); System.out.println(name); for(Object quote : (JSONArray)cat.get("favoriteQuotes")){ System.out.println(name + " says " + (String)quote); } If you continue to stick with JSON-Lib, I don't think the parsed representation would be much different from this. On Mar 16, 5:32 pm, chrysanthe m <[email protected]> wrote: > Hello > Two questions if I may: > 1. Will prototype process javascript "associative array" into JSON text? > 2. I am planning on processing a javascript array into JSON and sending > that over an AJAX call as a string. The problem is I cant figure out how to > "re-hydrate" that prototype process JSON string into either a JSON array or > a Java object server-side. I am using net.sf.json library. > > Any insight on either, or both, appreciated. -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
