Which JSON library does Webix use? I’ve created my JSON documents with both the Jackson Library and the org.json library. When I test for validity these libraries pass my object. But when I fetch the object to put into a datatable I get the following errors for some of the documents
JSON.parse: bad control character in string literal at line 1 column 260667 of the JSON data
If you can tell me which JSON parser you use then I can test the document with that first.
A bit more info: One of the lines that’s causing problems is this
the\r
Reserves Act 1977
My JSON parse passes this as \r
are valid, but when its loaded into the datatable using $$(“dt”).load(json) it throws an error. I can clean this up but I’m interested to know why datatable cannot parse it?
This has been entirely my fault! It has nothing to do with the parser in Webix datagrid!
The problem was caused because I was not escaping the JSON as it LEFT the DB to go to the datatable control. I escape it before I send it to the DB, the DB removed the escaping, so when I fetch it from the DB it was invalid JSON.
Here’s the fix if anyone else has this issue.
//Get the text from the DB
String rawJson = getJSONFromDB(id);
String escpJson=StringEscapeUtils.escapeJson(rawJson)
//Append to the javascript return string
js.append(""").append(name).append("":"").append(escpJson).append("",");
…
//Return the JSON to webix database
return js.toString().
Just for the info, Webix uses native JSON.pase API of a browser. So any valid JSON must be parsed correctly ( beware that it must be a JSON, not just an arbitrary js object )