I make an ajax call with jquery $.get() which returns a json array and it works fine on some cases. On other cases however, in Firefox i get a weird error saying (translated from german):
XML-processing error: syntax error
This is the structure of the json as shown in my servlet int the java console:
[{"key":"...","type":"...","content":"..."},
{"key":"...","type":"...","content":"..."},
...]
And this is the structure when logged in ff console using JSON.stringify():
[{\"key":\"...",\"type":\"...",\"content":\"..."},
{\"key":\"...",\"type":\"...",\"content":\"..."},
...]
My request simply looks like this:
$.get(url,
{"operation": "search", "searchText": searchText, "types": types, "resultNumber": 99},
function(data, status){
console.log(JSON.stringify(data));
});
My java method for creating the JSON array:
private JSONArray parseJSON (ArrayList<ResultObject> aResultList) throws JSONException
{
JSONArray resultJSONArray = new JSONArray();
for (ResultObject resultObject : aResultList)
{
JSONObject jsonObject = new JSONObject();
HashMap<String,String> fields = resultObject.getFields();
for (Map.Entry<String, String> entry : fields.entrySet())
{
jsonObject.put(entry.getKey(), entry.getValue());
}
resultJSONArray.put(jsonObject);
}
return resultJSONArray;
}
Whats going on here? Where are all these backslashes in the returned json coming from?
$.get()request please.