Python无法从PHP读取JSON解析

时间:2019-05-06 04:44:07

标签: php python json

我正在尝试将json的{​​{1}}格式的数据解析为python,反之亦然。 php

php

Python

$alternative_val = array(
    array(1, 0.5, 3),
    array(2, 1, 4),
    array(0.333, 0.25, 1)
  );
  $json = json_encode($alternative_val);
  $output = shell_exec('python spk.py "'.$json.'"');
  echo $output;

当我php = sys.argv[1] print(php) # 3x3 matrix X = [[1,0.5,3], [2 ,1,4], [0.333 ,0.25,1]] # result is 3x4 result = [[0,0,0], [0,0,0], [0,0,0]] # iterate through rows of X for i in range(len(php)): # iterate through columns of Y for j in range(len(php[0])): # iterate through rows of Y for k in range(len(php)): result[i][j] += php[i][k] * php[k][j] for r in result: print(r) 看起来与它的预期外观不同时(Python X),并且当我为其更改X变量时根本不起作用

从python打印(php)

print(php)

从python打印(X)

[[1,0.5,3],[2,1,4],[0.333000000000000018207657603852567262947559356689453125,0.25,1]] 

0 个答案:

没有答案