问题
The front end recieves the json output in the following format (with a backslash before the double quote). We didn't intentionally put the backspace but Primefaces(JSF) does when sending the output to front end. How to parse this and save it in an array using jquery or javascript? We don't want the backslash added by primefaces at all, if there is way we can do from the server side (Primefaces) please let me know. We can remove the "\" using some function in javascript but then it may remove any backslash if we gave it intentionaly. For example if i am sending double string like \"foo\"
{"topicJSON":"{\"topicBody\":[\"Test10\",\"Test22\",\"Test4\",\"Test11\"]}"}
Server Side
jGenerator.writeFieldName("topicBody"); jGenerator.writeStartArray(); ............... jGenerator.close(); context = RequestContext.getCurrentInstance();
context.addCallbackParam("topicJSON", out.toString());
回答1:
You can use jQuery.parseJSON
like this
var newOne = jQuery.parseJSON(yourJsOldVariable);//yourJsOldVariable contains that string you posted
来源:https://stackoverflow.com/questions/12196148/parsing-the-json-structure-with-backslash