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 9003289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:41:36+00:00 2026-06-16T00:41:36+00:00

I am playing with an api that just reads from my database and returns

  • 0

I am playing with an api that just reads from my database and returns the data in json format.

In phpMyAdmin the sentences are perfect (I used utf8_general to input a csv). Example:

    A line that uses 'r and special chars etc

But when I echo the json, I get this:

    A line that uses ///\\/\/\/r and special chars etc

First I got null object back so I used:

   mysql_set_charset('utf8', $link);

But I still get the corrupted data back.

Update:

Some more info:

mysql_set_charset('utf8',$link);

/* grab the posts from the db */
$query = "SELECT * FROM huren WHERE 1";

$result = mysql_query($query,$link) or die('Errant query:  '.$query);

// check row count 
$amount = mysql_num_rows($result);

/* create one master array of the records */
$houses = array();
if(mysql_num_rows($result)) {
    while($post = mysql_fetch_assoc($result)) {
        $houses[] = $post;
    }
}

/* output in necessary format */

    header('Content-type: application/json');
 $changed_json= str_replace('\\/', '/',json_encode(array('House'=>$houses)));
echo str_replace('\\\\', '\\',$changed_json);
  • 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-06-16T00:41:36+00:00Added an answer on June 16, 2026 at 12:41 am

    What’s with the replacing operations? json_encode either returns fully valid JSON representing the exact input you gave it, or it returns NULL because there were issues like your data not being in UTF-8. You should not do anything to the string returned by json_encode! If you didn’t get NULL, then you have won and just need to echo it.

    It will just work with this:

    header('Content-type: application/json');
    echo json_encode(array('House'=>$houses));
    

    The charset doesn’t really matter, since by default, json_encode produces pure ASCII output. This is because by default, unicode characters are represented in unicode escape sequences, e.g. \uxxxx

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

Sidebar

Related Questions

Am playing with Google Maps V3 API and StyledMarkers. The data is derived from
I’m just playing about with the data from a little Garmin GPS thingy I
I'm playing around with this Google Web toolkit/GSON example that gets data from twitter.
I'm playing a little bit with the new StackOverflow API . Unfortunately, my JSON
I'm am currently playing around with the third party facial recognition api from face.com.
I'm receiving multiple strings from a API and sometimes I have a string that
I'm playing with wikipedia API. I would like to get all country names from
I just started playing around with the Twitter Streaming API and using the command
Itry to learn a little bit JSON playing with facebook Graph API . What
I just started playing with the Google Map API for Static Images, and in

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.