javascript - Escape an already encoded json string -


at moment have work json strings quotes not correctly escaped. strings looks this

{ "foo" : "hello name "michael"" } 

is there realistic chance in js/php escape quotes in value without doing manually can parse string?

you haven't provided work with, looks you're generating json way:

$userinput = $_get['userinput']; $json = '{ "foo" : "' . $userinput . '" }'; 

this pretty bad. here's appropriate way generate json safely:

$outputdata = array(   "foo" => $_get['userinput'] ); $json = json_encode($outputdata); 

see reference here: http://php.net/manual/en/function.json-encode.php

as original question, there realistic chance in js/php escape quotes? no. suppose "actual value" of string series of paragraphs containing quote marks, know, continuation of quotation, each paragraph starts ". no, not able fixed.

you need fix source of json. if getting json string third-party service, need tell them strings sending not valid json.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -