Below is the code that I run in my Java compiler:
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
engine.put("person", "{name: 'Bob', favoriteColor: 'red'}");
System.out.println(engine.get("person.name"));
I expect it to be rated as "Bob", but instead it gives me null. If I try to print only the user object, it will correctly give me this result:
{name: 'Bob', favoriteColor: 'red'}
Why person.nameis it rated as null? Any help would be appreciated!
kshah source
share