Javascript, Ajax & JSON: weird "xml processing" error when parsing response

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:


And this is the structure when logged in ff console using JSON.stringify():


My request simply looks like this:

        {"operation": "search", "searchText": searchText, "types": types, "resultNumber": 99},
        function(data, status){

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());
        return resultJSONArray;

Whats going on here? Where are all these backslashes in the returned json coming from?

Looks like that you’r response is not processed by jQuery as you expected.
try to add a


as option for you’r request, also take care that you’r server-side set’s the right header on HTTP response (Content-Type: application/json)

because as I can see from you’r post, looks like that you pass a string to JSON.stringify

I hope that i help you, have a nice day