z*****e 发帖数: 74 | 1 【 以下文字转载自 Linux 讨论区 】
发信人: zteddie (独滑求伴(Blue+)), 信区: Linux
标 题: Help --- Parsing posted JSON data
发信站: BBS 未名空间站 (Mon Apr 2 17:02:19 2012, 美东)
Hi, I am trying to do following, not sure if it is possible:
1: On server one, posting data using:
curl -i -X POST -d 'json={
"disk": {
"root": "56%",
"tmp" : "4%",
"opt" : "7%",
"var" : "9%"
}
}'
2: On http server 2, a PHP script is used to capture the JSON data:
var_dump( $_POST['json'] );
$jsonObj = json_decode( $_POST['json'], true );
var_dump( $jsonObj );
?>
But dump $jsonObj is NULL.
I am new to JSON ... any idea what I am missing?
Thanks | s****y 发帖数: 983 | 2 you can't post json with nvp unless encrypted, so simply post a raw json
string
curl -i -X POST -d '{
"disk": {
"root": "56%",
"tmp" : "4%",
"opt" : "7%",
"var" : "9%"
}
}'
in php snippet, get json string with php://input
$json = json_decode(file_get_contents('php://input'), true ); |
|