You probably have to rethink your json structure - it doesn't look like you're interested in getting values from keys... you just want the values in the particular order.
Take a look at JSONArray On Thu, May 15, 2008 at 2:19 PM, Leon Derks <[EMAIL PROTECTED]> wrote: > Hi Chris, > > I just noticed that the options in the select are initialy not ordered. > But when I persist the options (groups) in my session data, the option are > ordered after I have clicked the search button and submitted the form. > Then refreshed page, contains a select with ordered group options. > > Do you have an explanation for this behaviour? > > Leon > > > > > Leon Derks wrote: > > > Thanks Chris, > > > > That worked. > > The only thing is that the order of groups in the select is gone. > > I know for sure I put them in the correct order in the java jsonObject. > > I think the var jsonObject = response.evalJSON(); or the for(var key in > jsonObject) messes up the order. > > Is there a way to solve this? > > > > For the ones interested, I fill my select box now in this way: > > > > Java Page: > > @OnEvent(component = "productSelect", value = "change") > > JSONObject onProductSelectChanged(String value) { > > ProductCategory category = > ProductCategory.getProductCategoryByName(value); > > groups = characteristicDAO.findGroupsByProductCategory(category); > > JSONObject jsonObject = new JSONObject(); > > for (CharacteristicGroup group : groups) { > > Long id = group.getId(); > > jsonObject.put(id.toString(), group.getName()); > > } > > return jsonObject; > > } > > > > javascript: > > function productSelectChanged(response) { > > var groupSelect = $('groupSelect'); > > clearSelectOption(groupSelect); > > var jsonObject = response.evalJSON(); > > for(var key in jsonObject) { > > addSelectOption(groupSelect, jsonObject[key], key, false); > > } > > } > > > > Chris Lewis wrote: > > > > > Try: > > > > > > for (var i in object) {} > > > > > > Where object would be your json object. > > > > > > Leon Derks wrote: > > > > > > > > > > Hi Sven, > > > > > > > > I only see that they get the value by using the key name. > > > > For example this: > > > > > > > > |var data = '{ "name": "Violet", "occupation": "character" > }'.evalJSON(); > > > > data.name; //prints Violet. > > > > | > > > > > > > > But in my case, I don't know the key name, so I can't get the value. > > > > Is there a way to get the key names of a JSON Object? > > > > For example something like this: > > > > | > > > > data.keys; //returns {name, occupation}| > > > > > > > > | > > > > | > > > > > > > > Leon > > > > > > > > > > > > Sven Homburg wrote: > > > > > > > > > > > > > http://www.prototypejs.org/learn/json > > > > > > > > > > 2008/5/15 Leon Derks <[EMAIL PROTECTED]>: > > > > > > > > > > > > > > > > > > > > > Hello > > > > > > > > > > > > I have a JSON object like this: > > > > > > > > > > > > JSONObject obj = new JSONObject(); > > > > > > > > > > > > obj.put(entity.getId(), entity.getName()); > > > > > > > > > > > > But how can I get the value from my json object in javascript, if > I > > > > > > don't > > > > > > know the key name? > > > > > > > > > > > > Is there a way to get the key name(s) from a json object in > javascript? > > > > > > > > > > > > Leon > > > > > > > > > > > > > --------------------------------------------------------------------- > > > > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > --------------------------------------------------------------------- > > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- Andreas Andreou - [EMAIL PROTECTED] - http://blog.andyhot.gr Tapestry / Tacos developer Open Source / JEE Consulting --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]