我有一个具有以下内容的大型JSON:
{"createTx": {
"inputs": [{
"address": "mtFYoSowT3i649wnBDYjCjewenh8AuofQb",
"value": 0.00009
}],
"outputs": [{
"address": "mmskWH7hG9CJNzb16JaVFJyWdgAwcVEAkz",
"value": 0.00018
}],
"fee": {
"address": "mmskWH7hG9CJNzb16JaVFJyWdgAwcVEAkz",
"value": 0.00023141
}}, "wifs" : [
"cUGddnJmuzfzpWXNwt1SRnQ8GMqZdQ1vg8BtwjG8f275pvExPzaX", "cSEjySAREyai8eQhgoqixzmxCeSP8QtbwHxptL8ijofg68ZMjoud", "cV2u6dqfiQthWfPixJ7ucFW5Tza1ubLr6ipM35vSTy9xGEKbCbaJ"]}
为了在CURL POST中运行它,我需要将其放入$ variable中,并采用以下格式:
$data = array("createTX" => "","inputs" => array ("1MfyBywPTSj9aAPr8cccCTcch71fd4vkDA" ) );
我需要在$ data变量中包含整个JSON。
答案 0 :(得分:0)
您正在寻找json_decode()
。
为了直接在PHP中使用此JSON字符串,请使用PHP的NOWDOC或HEREDOC语法,如下所示:
$json = <<< JSON
{"createTx": {
"inputs": [{
"address": "mtFYoSowT3i649wnBDYjCjewenh8AuofQb",
"value": 0.00009
}],
"outputs": [{
"address": "mmskWH7hG9CJNzb16JaVFJyWdgAwcVEAkz",
"value": 0.00018
}],
"fee": {
"address": "mmskWH7hG9CJNzb16JaVFJyWdgAwcVEAkz",
"value": 0.00023141
}}, "wifs" : [
"cUGddnJmuzfzpWXNwt1SRnQ8GMqZdQ1vg8BtwjG8f275pvExPzaX", "cSEjySAREyai8eQhgoqixzmxCeSP8QtbwHxptL8ijofg68ZMjoud", "cV2u6dqfiQthWfPixJ7ucFW5Tza1ubLr6ipM35vSTy9xGEKbCbaJ"]}
JSON;
$data = json_decode($json, true);