I create a huge JSON object and save it in my database. But when I load the “string” and echo into PHP, I cannot access the JSON object in jQuery. Do I have to consider something if I want to save my JSON object in a MySQL database (when I just create an array and then echo it using "echo json_encode ($ arr)", it works fine, but I need to save the object for caching).
{"247": {"0": "This is Question" "1": "," 2 ":" 247 "," 3 ":" 0 "," answers ": [[" Answer1 "," 960 ", "1"], ["Answer 2", "962", "0"], ["Answer 3", "961", "0"], ["Answer 4", "963", "0"]] }, {"248": {"0": "This is Question" "1": "," 2 ":" 247 "," 3 ":" 0 "," answers ": [[" Answer1 "," 960 "," 1 "], [" Answer 2 "," 962 "," 0 "], [" Answer 3 "," 961 "," 0 "], [" Answer 4 "," 963 "," 0 " ]]}}
just an excerpt
If I just repeat this JSON-Object, everything works fine, but if I load the same row from the database and the echo file, this will not work.
Update 1: forget to tell me that I am using the TEXT field with the setting UTF8_general_ci
Update 2: Maybe a little more code:
function start() {
$(".start").click(function () {
$.post("load_script.php", { }, function(data){
alert(data[247][0]);
}, "json");
return false;
});
}
loads the script and should warn "This is a question"
<?php
require_once('connect.php');
$ergebnis = mysql_query("SELECT text FROM cache_table ORDER BY RAND() LIMIT 1");
while($row = mysql_fetch_object($ergebnis)) {
$output = $row->text;
}
echo $output;
? >
this is a script where I load a database record using JSON-Object.
Update 3: I think I solved the problem. Some violation got into my JSON-Object, so I do this before exiting:
$output = str_replace("\n", "", $output);
$output = str_replace("\r", "", $output);
$output = str_replace("\r\n", "", $output);