When I was experimenting with opening JSON in Hash Link and Neko, I have noticed that standard “JsonParser.parse” won’t work out of the box. I have to write my own “wrapper” that uses this function inside, like this. Should we make it “built in” or leave it as it is, so that people would write workarounds, like I did? Like we have the JavaScript situation, where “btoa” doesn’t really work correctly and we have to write wrapper around it…
Forgot to mention that I read the file with “File.getContent” in neko/php/hl environments. However, this wrapper is unnecessary if the file was not encoded in UTF.
Here is the code:
class JaySon{
public static function parse(cont:String, filename='') {
function is(n:Int, what:Int) return cont.charCodeAt(n) == what;
return JsonParser.parse(cont.substr(
if (is(0, 65279))
/// looks like a HL target, skipping only first character here:
1
else if (is(0, 239) && is(1, 187) && is(2, 191))
/// it seems to be Neko or PHP, start from position 3:
3
else
/// all other targets, that prepare the UTF string correctly
0
));
}
}