Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 236325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:20:10+00:00 2026-05-11T20:20:10+00:00

I create a huge JSON-Object and save it in my database. But when I

  • 0

I create a huge JSON-Object and save it in my database. But when I load the “string” and echo it in PHP, I can’t 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 the Array and then echo it with “echo json_encode($arr);” it works fine, but I need to save the Object for caching).

{“247”:{“0″:”This is a
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 a
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 echo this JSON-Object, everything works fine, but if I load the same string from the database and echo it, it doesn’t work.

Update 1: forget to tell that I’m using a TEXT-Field with UTF8_general_ci collation

Update 2: Maybe a little bit more code:

function start() {
    $(".start").click(function () {

        $.post("load_script.php", { }, function(data){
            alert(data[247][0]);
        }, "json");

        return false;
    });
}

this loads the script and should alert “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 the script, where I load the database entry with the JSON-Object.

Update 3:
I think I solved the problem. Some break sneaked into my JSON-Object so I do this, before the output:

$output = str_replace("\n", "", $output);
$output = str_replace("\r", "", $output);
$output = str_replace("\r\n", "", $output);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:20:10+00:00Added an answer on May 11, 2026 at 8:20 pm

    I’d suggest looking at what your javascript is seeing. Instead of asking jQuery to interpret the json for you, have a look at the raw data:

    function start() {
        $(".start").click(function () {
    
            $.post("load_script.php", { }, function(data){
                    alert(data);
            }, "text");
    
            return false;
        });
    }
    

    For example, if part of the string gets oddly encoded because of the UTF-8, this might cause it to appear.

    Once you’ve done that, if you still can’t spot the problem, try this code:

    var data1, data2;
    function start() {
        $(".start").click(function () {
    
            $.post("load_script.php", {src: "db" }, function(data){
                    data1 = data;
            }, "text");
    
            $.post("load_script.php", {src: "echo" }, function(data){
                    data2 = data;
            }, "text");
    
            if (data1 == data2) {
               alert("data1 == data2");
            }
            else {
               var len = data1.length < data2.length ? data1.length : data2.length;
               for(i=0; i<len; ++i) {
                  if (data1.charAt(i) != data2.charAt(i)) {
                     alert("data1 first differs from data2 at character index " + i);
                     break;
                  }
               }
            }
    
            return false;
        });
    }
    

    And then change the PHP code to either return the data from the database or simply echo it, depending on the post parameters:

    <?php
       if ($_POST['src'] == 'db')) {
          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;
          }
       }
       else {
          $output = '{"247":{"0":"This is a 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 a question","1":"","2":"247","3":"0","answers":[["Answer1","960","1"],["Answer 2","962","0"],["Answer 3","961","0"],["Answer 4","963","0"]]}}';
       }
    
    echo $output;
    ?>
    

    Hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 182k
  • Answers 182k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It is reasonable to expect that you cannot do any… May 12, 2026 at 4:30 pm
  • Editorial Team
    Editorial Team added an answer I use the following code. It produces nicely-spaced steps for… May 12, 2026 at 4:30 pm
  • Editorial Team
    Editorial Team added an answer logging If you run the script repeatedly, the additional log… May 12, 2026 at 4:30 pm

Related Questions

I am using LINQ to access my database, and thereby gets a LINQ-created object
Do we really need a server side architecture to create a RIA application? My
I have a project involving a web voting system. The current values and related
I'm very new to JSON, and I need to parse some that an API

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.