1, today in the maintenance of the product catalog, found a wonderful thing, the Eval function conversion error, after the inspection found in the string if a newline character added will cause the problem.
2. Test procedure
Info.file
[{productdirids: ' 1 ', Productdirname: ' PC server '},{attributes: ' Hello
Nice '}]
public static void Main (string[] args) throws FileNotFoundException {
Scanner sc = new Scanner (New File (info.file "));
StringBuffer sb = new StringBuffer ();
Sb.append ("var json =eval (");
while (Sc.hasnextline ()) {
Sb.append (Sc.nextline ());
Sb.append ("\ n");//Note that comments out here can be performed normally, but if you add this sentence will cause an error, and under IE, the F12 console is not able to see the error.
}
Sb.append (");");
Sc.close ();
System.out.println (Sb.tostring ());
Sb.append ("Json[1].attributes");
Scriptenginemanager manager = new Scriptenginemanager ();
ScriptEngine engine = Manager.getenginebyname ("javascript");
try{
String Dynamicvalue = Engine.eval (sb.tostring ()). ToString ();
System.out.println (Dynamicvalue);
}catch (Scriptexception e) {
E.printstacktrace ();
}
}
The flaw of the Eval function