parsing the JSON structure with backslash

删除回忆录丶 提交于 2020-01-06 06:58:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!