I just realized that "string" and ""string"" are not same.
So it is not possible to replace " with ' in a string object (because we can't call it a string then).
If you want to replace latter:
public YailList RMethod(YailList yailList){
Object[] o = parse(yailList.toArray());
return YailList.makeList(o);
}
public Object[] parse(Object[] arr){
Object[] rArr = new Object[arr.length];
for (int i=0;i<arr.length;i++){
Object o = arr[i];
if (o instanceof String){
rArr[i] = o.toString().replace("\"","'");
}else if(o instanceof Object[]){
Object[] innerArr = (Object[]) o;
rArr[i] = parse(innerArr);
}else {
rArr[i] = o;
}
}
return rArr;
}
See attached a working aia project for a pie chart, and the java code used to build the extension. Note: this uses the blocks procedure to convert the AI2 list to the correct string.
And extension passes that value to js which is run in WebView.
There are some issues with string conversion between Java and JavaScript.
When you run a js query in WebView to return a string result then you will get that value as already escaped (wrapped in ").
Similarly when you pass a string either wrapped in " or ', that's actually treated as String in JavaScript.
For example, see this snippet from @Taifun (He can shed more light on this topic):
So to conclude this I would say "'string'" (Java) is treated as "string" in JavaScript and "string" (JavaScript) is treated as ""string"" in Java.
The String htmlcode is constructing a long string of html to be set to file which is then run in a webviewer.
All I want to do is add a string as a variable to that html. As you have seen this works if I send a string by converting the list in the app, but it would be better to get users to simply add the list to the extension blocks, and then convert the "list" (whatever it is) to a string in the java code.
Java, for whatever reason, does not appear to want to do this, without having to iterate over the items in the list, even though this appears trivial when using blocks.....
Only method which I can think is going to work is to iterate over each item and wrap that in ' .
Or you actually don't need to do anything.Because " and ' are same in JavaScript.
Through trial and error, prompted by your inputs, I discovered that by setting the "list" to a String in the Simple Function, it was automatically converted it to a string, and with @vknow360 's help found that I could ignore the " that I wanted to be ' . All is well, although I could be a lot further along if I had found this in the first place. Oh well