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);
Marc B
  • 356,200
  • 43
  • 426
  • 500
user3469432
  • 31
  • 1
  • 6

2 Answers2

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

Community
  • 1
  • 1
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/')));
jeroen
  • 91,079
  • 21
  • 114
  • 132