java - What does Rhino accept as valid names for object properties? -


i trying process data nativeobject, have found small issue naming of object properties. javascript code object is:

var mainobject = {     "innerobject" : {         "234" : {             "property1" : "1",             "property2" : "2"         }     } } 

the method use process in java looks this:

public void processnative(nativeobject obj) {      if(nativeobject.hasproperty(obj, "innerobject")) {         nativeobject no = (nativeobject)nativeobject.getproperty(obj, "innerobject");         object[] propids = nativeobject.getpropertyids(no);         (int = 0; < propids.length; i++) {             string key = propids[i].tostring();              nativeobject numobj = (nativeobject)nativeobject.getproperty(no, key);              //do more processing here         }     } } 

this code throw exception: java.lang.classcastexception: org.mozilla.javascript.uniquetag cannot cast org.mozilla.javascript.nativeobject.

if cast uniquetag can proper value, in case uniquetag.not_found.

i find bit confusing since getting property key object , exists in javascript code.

if change name of object "234" "car" code works expected, assuming there issue naming. post understand property names can type of string, there should no problems having string made of digits.

so guess follow-up question be: there way me solve issue without having renaming?

one more thing need mention have access javascript code , java method. else black box.

thanks!

i had problem in scala too. nativeobject supports 2 methods get(int, scritable) , get(string, scriptable). if property key number string convert int , use get(int, yourobject)

http://www.jarvana.com/jarvana/view/org/mozilla/rhino/1.7r3/rhino-1.7r3-javadoc.jar!/org/mozilla/javascript/scriptableobject.html#get%28int,%20org.mozilla.javascript.scriptable%29


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -