php - how to force the server to respond as json

I had a problem withStreamBuilder
in flutter app here Geting data from mysql to StreamBuilder Flutter
and now I want to force the server to pass the data as JSON this my php codedb.php
<?php
$dns = 'mysql:host=localhost;dbname=id13424627_flutter';
$user = 'id13424627_flutter_app';
$pass = 'Flutter_maen12';
try{
$db = new PDO ($dns, $user, $pass);
echo 'connected';
}catch( PDOException $e){
$error = $e->getMessage();
echo $error;
}
get.php
<?php
require_once('db.php');
$query = 'SELECT * FROM flutter';
$stm = $db->prepare($query);
$stm->execute();
$row = $stm->fetch(PDO::FETCH_ASSOC);
echo json_encode($row);
Answer
Solution:
Try to delete this anecho 'connected';
and add the top of your get.php file;
header("Content-type: application/json; charset=utf-8");
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: call to undefined function illuminate\encryption\openssl_cipher_iv_length()
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.