2

i want to connect to a database server using php , and then echo the data as JSON so later i can use it in android but JSON shows / as \/ for example if http://www.google.com/ was in the database if shows it as

"http:\/\/www.google.com\/" .

i made connections and all and here is how i fetch the data

try {
    $stmt   = $db->prepare($query);
    $result = $stmt->execute($query_params);
}catch (PDOException $ex) {
    $response["success"] = 0;
    $response["message"] = "Database Error1. Please Try Again!";
    die(json_encode($response));
}
while($row = $stmt->fetch(PDO::FETCH_ASSOC))
$array[] = $row;
echo json_encode($array);
4
  • You must have added slashes before placing in the database, use php.net/manual/en/function.stripslashes.php Commented Jul 17, 2014 at 15:31
  • i use that after the while , on the row string , it say's u must use it on a string not an array , i dont know where to put it Commented Jul 17, 2014 at 15:37
  • either you're on a stone-age PHP with register_globals enabled, or you're double-escaping going into the DB or pulling out of the db. Commented Jul 17, 2014 at 15:39
  • and i didnt know JSON encoded in that way , sorry Commented Jul 17, 2014 at 15:44

2 Answers 2

1

This is valid json and the correct way to encode it, see http://codepad.viper-7.com/6PbdmJ

When you decode it in for example javascript or php, you will get your original URL back:

javascript:

JSON.parse('"http:\/\/www.google.com\/"');

php:

var_dump(json_decode(json_encode('http://www.google.com/')));
Sign up to request clarification or add additional context in comments.

Comments

1

You need to decode you json ... run that PHP example and you will understand what i mean:

$encode = json_encode("https://www.google.com/");

echo $encode;

echo "<br />";

echo json_decode($encode,true);

so, if you sending encoded json, you should decode it in android to use it properly.

This link should help: How to parse JSON in Android

Comments

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.