Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php json_decode生成一个字符串_Php_Python_Json - Fatal编程技术网

Php json_decode生成一个字符串

Php json_decode生成一个字符串,php,python,json,Php,Python,Json,下面是一个小php代码,它尝试读取.json文件,提取内容,然后将其转换为数组 相反,我得到了一个字符串 json.file是在下面的python代码中创建的 python脚本 dict_test= {'Subcellular': ['Ribosome', 'Plasma Membrane'], 'CAS': ['56-85-9', '50-99-7'], 'Bio_target': ['RNA 18S', 'Insuline receptor'], 'strain': ['', ''], 'U

下面是一个小php代码,它尝试读取.json文件,提取内容,然后将其转换为数组

相反,我得到了一个字符串

json.file是在下面的python代码中创建的

python脚本

dict_test= {'Subcellular': ['Ribosome', 'Plasma Membrane'], 'CAS': ['56-85-9', '50-99-7'], 'Bio_target': ['RNA 18S', 'Insuline receptor'], 'strain': ['', ''], 'Unity': ['J', 'nM'], 'value': ['-80', '0.01'], 'InchI': ['1S/C5H10N2O3/c6-3(5(9)10)1-2-4(7)8/h3H,1-2,6H2,(H2,7,8)(H,9,10)\\xa0', '1S/C6H12O6/c7-1-2-3(8)4(9)5(10)6(11)12-2/h2-11H,1H2/t2-,3-,4+,5-,6?/m1/s1\\xa0'], 'Conditions': ['Temperature of 25\\xbaC and normal pressure', 'Computational simulation in R module canislup'], 'Link\\n': ['www.soulink.pt\\n', 'www.sououtro.pt\\n'], 'Asay_parameter': ['enthalpy', 'concentration'], 'Smiles': ['O=C(N)CCC(N)C(=O)O', 'OC[C@H]1OC(O)[C@H](O)[C@@H](O)[C@@H]1O'], 'Journal': ['Nature', 'Science'], 'Experimental_error': ['0.01 J', '0.05 uM'], 'Title': ['Glutamine is a novel compound in Brainstem studies', 'Glucose concetration is essential to calcium inducted waves'], 'Assay_ID': ['12345', '123456'], 'Cell_type': ['Neuron', 'Myocite'], 'Comparisons': ['enthalpy>70 J', 'Concentration< 10 uM'], 'Mol_name': ['Glutamine', 'Glucose'], 'target_type': ['Peptide', 'Protein'], 'LAB': ['IMED', 'Lasige'], 'Tissue': ['Brainstem', 'Pericardium'], 'Species': ['Homo sapiens', 'Canis lupus'], 'Observations': ['Outliers were not found', 'Python modules were also used']}

utf=unicode(dic_test)
output_file= 'aaa.txt'+'.json'
import json
with open(output_file, 'wb') as fp:
    json.dump(utf, fp)
[代码>Dic>Dic>Dic>Dic测试:{亚细胞的测试:{亚细胞:['核糖体','核糖体','50-85-9 9',50-99-7-7','生物的目标','生物的目标':[RNA 18S','生物的测试:{Dic>测试:{DiC.5-85-85-9-9-9-9”,“50-99-9-9-9-9”,“50-9-9-9-9-7',,,“50-9-9-9-9-9-9-9-7”,“生物的目标','生物的目标','生物的目标:['生物的目标:['RNA 18RNA 18RNA 18RNA 18S的目标:['RNA 18S','RNA 18S,”RNA 18S,”RNA 18S','RNA 18S'','RNA 18S','RNA 18S','RNA 18S'','RNA 18S第6(11)条12-2/h2-11H,1H2/t2-,3-,4+,5-,6?/m1/s1\\xa0'],“条件”:[“25℃的温度和正常压力”,“R模块canislup中的计算模拟”],“链接\\n':[“www.soulink.pt\\n”,“www.sooutro.pt\\n'],“Asay_参数”:[“焓”,“浓度”],“微笑”:[“O=C(n)CCC(n)C(=O)O),“OC”[C@H]1OC(O)[C@H](O) [C@@H](O)[C@@H]1O'],《自然》、《科学》、《实验误差》:[“0.01 J”、“0.05μm”],《标题》:[“谷氨酰胺是脑干研究中的一种新化合物”;“葡萄糖浓度对钙诱导波至关重要”],《分析ID》:[“12345”、“123456”],“细胞类型”[“神经元”、“心肌”],“比较”:[“焓>70 J”,“浓度<10μm”],“摩尔名称”:[‘谷氨酰胺’、‘葡萄糖’]、‘目标类型’:[‘肽’、‘蛋白质’]、‘实验室’:[‘定时’、‘激光’]、‘组织’:[‘脑干’、‘心包’]、‘物种’:[‘智人’、‘犬狼疮’]、‘观察’:[‘未发现异常值’、‘还使用Python模块’]} utf=unicode(dic_测试) 输出文件='aaa.txt'+'.json' 导入json 以fp形式打开(输出_文件“wb”): json.dump(utf,fp) .json文件

"{'Subcellular': ['Ribosome', 'Plasma Membrane'], 'CAS': ['56-85-9', '50-99-7'], 'Bio_target': ['RNA 18S', 'Insuline receptor'], 'strain': ['', ''], 'Unity': ['J', 'nM'], 'value': ['-80', '0.01'], 'InchI': ['1S/C5H10N2O3/c6-3(5(9)10)1-2-4(7)8/h3H,1-2,6H2,(H2,7,8)(H,9,10)\\xa0', '1S/C6H12O6/c7-1-2-3(8)4(9)5(10)6(11)12-2/h2-11H,1H2/t2-,3-,4+,5-,6?/m1/s1\\xa0'], 'Conditions': ['Temperature of 25\\xbaC and normal pressure', 'Computational simulation in R module canislup'], 'Link\\n': ['www.soulink.pt\\n', 'www.sououtro.pt\\n'], 'Asay_parameter': ['enthalpy', 'concentration'], 'Smiles': ['O=C(N)CCC(N)C(=O)O', 'OC[C@H]1OC(O)[C@H](O)[C@@H](O)[C@@H]1O'], 'Journal': ['Nature', 'Science'], 'Experimental_error': ['0.01 J', '0.05 uM'], 'Title': ['Glutamine is a novel compound in Brainstem studies', 'Glucose concetration is essential to calcium inducted waves'], 'Assay_ID': ['12345', '123456'], 'Cell_type': ['Neuron', 'Myocite'], 'Comparisons': ['enthalpy>70 J', 'Concentration< 10 uM'], 'Mol_name': ['Glutamine', 'Glucose'], 'target_type': ['Peptide', 'Protein'], 'LAB': ['IMED', 'Lasige'], 'Tissue': ['Brainstem', 'Pericardium'], 'Species': ['Homo sapiens', 'Canis lupus'], 'Observations': ['Outliers were not found', 'Python modules were also used']}"
“{‘亚细胞’:[‘核糖体’、‘质膜’]、‘CAS’:[‘56-85-9’、‘50-99-7’]、‘生物靶点’:[‘RNA 18S’、‘胰岛素受体’]、‘菌株’:[‘’、‘单位’:[‘J’、‘nM’]、‘值’:[‘-80’、‘0.01’、‘InchI’:[‘1S/C5H10N2O3/c6-3(5(9)10)1-2-4(7)8/h3H、1-2、6H2、‘H2、7、8’、‘H、10’、‘H、10’、‘H10.01’、‘Xa8’、‘8’、‘Xa8’、‘6(11(Xa8)6(8)6(11(8)6(8)6(8)6(8)6(8)6(11(8)6(812-2/h2-11H,1H2/t2-,3-,4+,5-,6?/m1/s1\\xa0'],“条件”:[“25℃的温度和正常压力”,“R模块canislup中的计算模拟”],“链接\\n':[“www.soulink.pt\\n”,“www.sooutro.pt\\n'],“Asay_参数”:[“焓”,“浓度”],“微笑”:[“O=C(n)CCC(n)C(=O)O),“OC”[C@H]1OC(O)[C@H](O) [C@@H](O)[C@@H]1O'],《自然》、《科学》、《实验误差》:[“0.01 J”、“0.05μm”],《标题》:[“谷氨酰胺是脑干研究中的一种新化合物”;“葡萄糖浓度对钙诱导波至关重要”],《分析ID》:[“12345”、“123456”],“细胞类型”[“神经元”、“心肌”],“比较”:[“焓>70 J”,“浓度<10μm”],“摩尔名称”:[‘谷氨酰胺’、‘葡萄糖’]、‘目标类型’:[‘肽’、‘蛋白质’]、‘实验室’:[‘定时’、‘激光’]、‘组织’:[‘脑干’、‘心包’]、‘物种’:[‘智人’、‘犬狼疮’]、‘观察’:[‘未发现异常值’、‘还使用了Python模块’]}
php

<?php

$string = file_get_contents("aaa.txt.json");
$json = json_decode($string, true);


var_dump($json);


?>


php的输出是一个字符串。

来自php文档:

//名称和值必须用双引号括起来
//单引号无效

从python脚本创建的Json无效。您需要对名称使用双引号,并去掉链接中的//n

{"Subcellular": ["Ribosome", "Plasma Membrane"], "CAS": ["56-85-9", "50-99-7"], "Link": ["www.soulink.pt", "www.sououtro.pt"], "Bio_target": ["RNA 18S", "Insuline receptor"], "strain": ["", ""], "Unity": ["J", "nM"], "LAB": ["IMED", "Lasige"], "InchI": ["1S/C5H10N2O3/c6-3(5(9)10)1-2-4(7)8/h3H,1-2,6H2,(H2,7,8)(H,9,10)\\\\xa0", "1S/C6H12O6/c7-1-2-3(8)4(9)5(10)6(11)12-2/h2-11H,1H2/t2-,3-,4+,5-,6?/m1/s1\\\\xa0"], "Conditions": ["Temperature of 25\\\\xbaC and normal pressure", "Computational simulation in R module canislup"], "Asay_parameter": ["enthalpy", "concentration"], "Smiles": ["O=C(N)CCC(N)C(=O)O", "OC[C@H]1OC(O)[C@H](O)[C@@H](O)[C@@H]1O"], "Journal": ["Nature", "Science"], "Title": ["Glutamine is a novel compound in Brainstem studies", "Glucose concetration is essential to calcium inducted waves"], "Experimental_error": ["0.01 J", "0.05 uM"], "Assay_ID": ["12345", "123456"], "Cell_type": ["Neuron", "Myocite"], "Comparisons": ["enthalpy>70 J", "Concentration< 10 uM"], "Mol_name": ["Glutamine", "Glucose"], "target_type": ["Peptide", "Protein"], "value": ["-80", "0.01"], "Tissue": ["Brainstem", "Pericardium"], "Species": ["Homo sapiens", "Canis lupus"], "Observations": ["Outliers were not found", "Python modules were also used"]}
{“亚细胞”:[“核糖体”,“质膜”],“CAS”:[“56-85-9”,“50-99-7”],“链接]:[“www.soulink.pt”,“www.sooutro.pt”],“Bio_靶标”:[“RNA 18S”,“胰岛素受体”],“菌株”:[“,”,“,”,“统一性”:[“J”,“nM”,“LAB:“IMED”,“Lasige”,“InchI”:[“1S/C5H10N2O3/c6-3(5(9)10)1-4(7)8/H,1-2,1-2,(H38,10),“,”,“1S/C6H12O6/c7-1-2-3(8)4(9)5(10)6(11)12-2/h2-11H,1H2/t2-,3-,4+,5-,6-/m1/s1\\\\\\\xa0”],“条件”:[“25\\\\\\\\xbaC的温度和正常压力”,“R模块canislup中的计算模拟”],“Asayï参数”:[“焓”,“浓度”],“微笑”:[“O=C(N)CCC(N)C(=O)O),“OC”[C@H]1OC(O)[C@H](O) [C@@H](O)[C@@H]1O“,“杂志”:[“自然”《科学》,“标题”:[“谷氨酰胺是脑干研究中的一种新化合物”,“葡萄糖浓度对钙诱导波至关重要”],“实验误差”:[“0.01 J”,“0.05μm”],“分析ID”:[“12345”,“123456”],“细胞类型”:[“神经元”,“心肌细胞”],“比较”:[“焓>70 J”,“浓度<10μm”],“摩尔名称”:[“谷氨酰胺”,“葡萄糖”,”目标类型:“[“肽”,“蛋白质”],“值”:[“-80”,“0.01”],“组织”:[“脑干”,“心包”],“物种”:[“智人”,“犬狼疮”],“观察结果”:[“未发现异常值”,“也使用Python模块”]}
在如上所述更改Json后,php将正常工作

$string = file_get_contents("aaa.txt.json");
$json = json_decode($string, true);
echo "<pre>";
print_r($json);
echo "</pre>";
$string=file\u get\u contents(“aaa.txt.json”);
$json=json_decode($string,true);
回声“;
打印(json);
回声“;

您给了
json.dump()
一个字符串,那么您期望得到什么呢?使用未使用的
dict\u测试的原因是什么呢?顺便问一下,Python或PHP的哪种行为让您感到惊讶?如果您按照指南的要求将示例的代码量减少到最小,这甚至不是问题。