This is my code so far
$dataraw = $_SESSION['image'];
$datagambar = json_encode($dataraw);
echo '<pre>';
print_r($dataraw);
echo '</pre>';
print($escaped_json);
$type1 = gettype($dataraw);
print($type1);
$type2 = gettype($datagambar);
print($type2);
This is $dataraw output, the type is array
Array
(
[0] => Array
(
[FileName] => 20221227_202035.jpg
[Model] => SM-A528B
[Longitude] => 106.904251
[Latitude] => -6.167665
)
[1] => Array
(
[FileName] => 20221227_202157.jpg
[Model] => SM-A528B
[Longitude] => 106.9042428
[Latitude] => -6.1676580997222
)
)
This is $datagambar output, the type is string
[{"FileName":"20221227_202035.jpg","Model":"SM-A528B","Longitude":106.904251,"Latitude":-6.167665},{"FileName":"20221227_202157.jpg","Model":"SM-A528B","Longitude":106.9042428,"Latitude":-6.167658099722223}]
Pass to python
echo shell_exec("D:\Anaconda\python.exe D:/xampp/htdocs/Klasifikasi_KNN/admin/test.py $datagambar");
This is my python test.py
import sys, json
import os
import pymysql
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import mplcursors as mpl
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score,hamming_loss,classification_report
json_list = []
escaped_json1 = sys.argv[1]
# this is working but its only a string of array json
# print(escaped_json1)
# this is working but its only a string of array json
json_list.append(json.loads(escaped_json1))
parsed_data = json.loads(escaped_json1)
print(json_list)
print(parsed_data)
When i do print(escaped_json1) it display a string of array json from php($datagambar).
python output:
Hello world has been called [{"FileName":"20221227_202035.jpg","Model":"SM-A528B","Longitude":106.904251,"Latitude":-6.167665},{"FileName":"20221227_202157.jpg","Model":"SM-A528B","Longitude":106.9042428,"Latitude":-6.167658099722223}]
I use apache as my server with phpmyadmin and anaconda.
T tried using print(type(escapedjson1)) or print(type(escapedjson1)) but it doesn't display the type
json.loads didn't change the type of data to python array
How to loads it and make the string array into a variable array so i can call it and convert it to dataframe?.
$datagambarvariable as a single argument, which is why you can see some output when you print it, but fails to parse as it may not be valid JSON, you can try wrapping the variable in single quotes:echo shell_exec("D:\Anaconda\python.exe D:/xampp/htdocs/Klasifikasi_KNN/admin/test.py '$datagambar'");pcntl_exec(), where you don't put a shell in the middle, but that function is POSIX-only, I'm afraid.print(type(escaped_json1))