1

I am retrieving json from a php file that connects to the database and then creates the json to be imported into my page via an ajax call.

Some of the database columns have file paths in them, ie images/myfolder/myfile

The json that I see when I open the page in a web browser formats the file path like this:

\/images\/myfolder\/myfile

Are the escaped characters going to break the json?

i.e, if i do var icon_image = myData.file

will icon_image hold: \/images\/myfolder\/myfile or /images/myfolder/myfile

I am hoping the second option from above, but if it doesn't how do I get it to display as /images/myfolder/myfile

I have put mb_internal_encoding( 'UTF-8' ); at the top of the php page

The script that generates the json is as follows:

mb_internal_encoding( 'UTF-8' );
mysql_select_db($database_growth_conn, $growth_conn);
$query_rs_icons = sprintf("SELECT * FROM icons_ico ORDER BY name_ico");
//echo($query_rs_icons);
$rs_icons = mysql_query($query_rs_icons, $growth_conn) or die(mysql_error());
$row_rs_icons = mysql_fetch_assoc($rs_icons);
$totalRows_rs_icons = mysql_num_rows($rs_icons)
$rows = array();

while($r = mysql_fetch_assoc($rs_icons)) {
    $rows[] = $r;
}

$jsondata = json_encode($rows);
echo '{"icons":'.$jsondata.'}';
2
  • Why would they break the json? What gives you the idea it would? I don't understand. Commented Nov 10, 2010 at 13:21
  • just because in the output on the browser it has \/ i reaslised it was an escaped character but was not sure how json dealt with it. so thats why i asked the question, just searching for knowledge! Commented Nov 10, 2010 at 14:18

1 Answer 1

1

are the escaped characters going to break the json?

No. A backslash-escaped non-special punctuation is just the same as the punctuation itself. The JS string literals "a/b" and "a\/b" result in the same string value, a/b.

json_encode escapes the forward slash character for you so that if you try to include a string with the sequence </script> in it in a script element, it doesn't prematurely end the script block.

Sign up to request clarification or add additional context in comments.

1 Comment

nice thanks, i wanted to check before i started doing the jquery that was going to use it,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.