0

前端接收以下格式的 json 输出(双引号前带有反斜杠)。我们没有故意放退格键,但 Primefaces(JSF) 在将输出发送到前端时会这样做。如何使用 jquery 或 javascript 解析并将其保存在数组中?我们根本不希望 primefaces 添加反斜杠,如果我们可以从服务器端(Primefaces)做任何事情,请告诉我。我们可以使用 javascript 中的某些函数删除“\”,但是如果我们故意给它,它可能会删除任何反斜杠。例如,如果我发送像 \"foo\" 这样的双字符串

{"topicJSON":"{\"topicBody\":[\"Test10\",\"Test22\",\"Test4\",\"Test11\"]}"}

服务器端

jGenerator.writeFieldName("topicBody");             jGenerator.writeStartArray();                  ...............             jGenerator.close();              context = RequestContext.getCurrentInstance();           
 context.addCallbackParam("topicJSON", out.toString());   
4

1 回答 1

0

您可以使用jQuery.parseJSON

像这样

var newOne = jQuery.parseJSON(yourJsOldVariable);//yourJsOldVariable contains that string you posted
于 2012-08-30T12:15:19.407 回答