note 116775 added to function.json-encode
| From: | bibilkattathara15 at gmail dot com | Date: | Thu, 26 Feb 2015 09:21:46 +0000 |
| Subject: | note 116775 added to function.json-encode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201812@lists.php.net to get a copy of this message | ||
The json_encode() does'nt gave you correct json I have written a code that can give a valid
json
//DatabaseConnectionClass.php
abstract class DatabaseConnectionClass {
protected $link;
protected function __construct()
{
$this->link=mysqli_connect('localhost','root','','realestate')
or die('Unable to connect to database');
}
}
//JSON.php
include 'DatabaseConnectionClass.php';
class JSON extends DatabaseConnectionClass
{
private $recordCount;
function __construct()
{
// Used for Connecting to Database
parent::__construct();
$this->recordCount=0;
}
private function jsonFileWriter($buffer_string,$mode)
{
// This function is to write data onto a file.
$jsonFile=fopen("data.json",$mode);
fwrite($jsonFile, $buffer_string);
fclose($jsonFile);
}
public function generateJSON()
{
/* Used to generate data for Angular JS JSON File*/
/*Refer ExportJson.class in phpMyAdmin*/
$res=$this->link->query('SELECT
id,district,taluk,category,type,description,amount
FROM tbl_info WHERE 1');
while ($row=$res->fetch_assoc())
{
$this->recordCount=$this->recordCount+1;
if($this->recordCount==1)
{
$buffer='[';
$this->jsonFileWriter($buffer,'w');
}
else
{
$buffer = ', ';
$this->jsonFileWriter($buffer,'a');
}
$json=json_encode($row, JSON_PRETTY_PRINT, 512);
$this->jsonFileWriter($json,'a');
}
$buffer = '] ';
$this->jsonFileWriter($buffer,'a');
}
}
----
Server IP: 72.52.91.14
Probable Submitter: 101.63.221.117
----
Manual Page -- http://php.net/manual/en/function.json-encode.php
Edit -- https://master.php.net/note/edit/116775
Del: integrated -- https://master.php.net/note/delete/116775/integrated
Del: useless -- https://master.php.net/note/delete/116775/useless
Del: bad code -- https://master.php.net/note/delete/116775/bad+code
Del: spam -- https://master.php.net/note/delete/116775/spam
Del: non-english -- https://master.php.net/note/delete/116775/non-english
Del: in docs -- https://master.php.net/note/delete/116775/in+docs
Del: other reasons-- https://master.php.net/note/delete/116775
Reject -- https://master.php.net/note/reject/116775
Search -- https://master.php.net/manage/user-notes.php