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)
Comments
Post a Comment