When using an upload php script with AS3 and now with JavaScript, I encountered a test feature that should return this if everything is okay:
{"erro":"OK","msg":"","descr":"op:ini,urlArq:\/Library\/WebServer\/Documents\/www\/sintran\/fotos\/teste.log"}
However, the JavaScript code is throwing an error: JSON Parse error: Single quotes (') are not allowed in JSON
It's clear from the response that there are no single quotes present. It's possible that the "descr" property might be causing confusion due to certain characters like : and ,, but I prefer not to alter it so that AS3 can continue reading this property (since it contains useful data).
Any thoughts on how to resolve this issue?
Edit: The slashes are properly escaped with backslashes, although they are not displaying correctly above.
Edit: Here is the code snippet for reference:
formUpload.prototype.ini_test = function(evt){
console.log("ini_test - Server response: "+evt.target.responseText);
var jsonRes = evt.target.responseText;
jsonRes = jsonRes.slice(jsonRes.indexOf("{"), jsonRes.lastIndexOf("}")+1);
try{
var Res = JSON.parse(jsonRes);
if(Res.erro!="OK"){
this.monitor_ini.innerHTML = "Error: "+Res.msg;
} else {
this.monitor_ini.innerHTML = "";
var jExts = this.form.arquivo_tipos.value;
this.Exts = JSON.parse(jExts);
this.monitor_info.innerHTML = this.ajuda();
}
} catch(e){
this.monitor_ini.innerHTML = "Error!";
console.log("formUpload ini_test Error: "+e.message+" Server response: "+jsonRes);
alert("Upload test error. JavaScript response: "+e.message);
}
}
Edit: Logging all results to console log - however, this time I tried without escaping slashes, resulting in a different final string:
ini_test - Server response: {"erro":"OK","msg":"","descr":"op:ini,urlArq:\/Library\/WebServer\/Documents\/www\/sintran\/fotos\/teste.log"}
formUpload ini_test Error: JSON Parse error: Single quotes (') are not allowed in JSON Server response: {"erro":"OK","msg":"","descr":"op:ini,urlArq:/Library/WebServer/Documents/www/sintran/fotos/teste.log"}