I've generated an array like below.But unable to parse it in json_encode.Am I missing anything here? please let me know.
PHP code :
<?php
$i=0;
$result = shell_exec('scripts/fetch_script.sh');
foreach(preg_split("/((\r?\n)|(\r\n?))/", $result) as $line)
{
parse_str($line);
}
$stat = "array(";
$lines = file('parameter.file');
foreach ($lines as $line) {
$v = explode('|', strtoupper($line));
$str = '$v[1]';
eval("\$str = \"$str\";");
eval("\$str = \"$str\";");
$calc = eval("return round(($str),2);");
$stat .="'$v[0]' => $calc,";
}
$stat .=");";
echo json_encode($stat);
?>
But output shows like Below which is not in json format:
"array('QUERY_CACHE_USAGE' => 0,'DISK_TMP_TABLES_USAGE' => 1.52,'QUERY_CACHE_USAGE' => 0,'DISK_TMP_TABLES_USAGE' => 1.52,'QUERY_CACHE_USAGE' => 0,'DISK_TMP_TABLES_USAGE' => 1.52,'QUERY_CACHE_USAGE' => 0,'DISK_TMP_TABLES_USAGE' => 1.52,'QUERY_CACHE_USAGE' => 0,'DISK_TMP_TABLES_USAGE' => 1.52,'QUERY_CACHE_USAGE' => 0,'DISK_TMP_TABLES_USAGE' => 1.52,'QUERY_CACHE_USAGE' => 0,'DISK_TMP_TABLES_USAGE' => 1.52,'QUERY_CACHE_USAGE' => 0,'DISK_TMP_TABLES_USAGE' => 1.52,'QUERY_CACHE_USAGE' => 0,'DISK_TMP_TABLES_USAGE' => 1.52,'QUERY_CACHE_USAGE' => 0,'DISK_TMP_TABLES_USAGE' => 1.52,'QUERY_CACHE_USAGE' => 0,'DISK_TMP_TABLES_USAGE' => 1.52,'QUERY_CACHE_USAGE' => 0,'DISK_TMP_TABLES_USAGE' => 1.52,);"
json_encodeworks for an array, not string. Change your code to make array instead of stringeval()for everything? And why is not "script" not return proper JSON to begin with?