我有这个代码a.json
:
{
"body" : {
"outboundSMSMessageRequest": {
"address": [
"9456654978" /* 1 */
],
"senderAddress": " 64735 ", /* 3 */
"outboundSMSTextMessage": {
"message": "Welcome to fgf Your Confirmation Code - " /* 2 */
},
"clientCorrelator": "1", /* 4 */
"receiptRequest": {
"notifyURL": "2", /* 5 */
"callbackData": "3" /* 6 */
},
"senderName": "4" /* 7 */
}
}
}
我想打印上面标记的值(1、3、2、4、5、6、7,仅值)。我试过这个:
$jsonData = file_get_contents("a.json");
$json = json_decode($jsonData,true);
echo $json;
但我最终得到以下通知:
PHP 注意:数组到字符串的转换
如何根据需要打印值?
大概是:
我想在一个 PHP 页面中打印(1、3、2、4、5、6、7,仅值)
...你的意思是你用编号的注释标记的那些值,例如/* 1 */
- 如果是这样,这应该可以解决问题(无论如何都要回显出来)。
$jsonData = file_get_contents("a.json");
$o = json_decode($jsonData);
$outboundSMSRequest = $o->body->outboundSMSMessageRequest;
echo $outboundSMSRequest->address[0] . "\n" // outbound address
. $outboundSMSRequest->outboundSMSTextMessage->message . "\n" // outbound message
. $outboundSMSRequest->senderAddress . "\n" // sender address
. $outboundSMSRequest->clientCorrelator . "\n" // client correlator
. $outboundSMSRequest->receiptRequest->notifyURL . "\n" // notification URL
. $outboundSMSRequest->receiptRequest->callbackData . "\n" // callback data
. $outboundSMSRequest->senderName; // sender name
当您使用时,json_decode()
您将 JavaScript 对象转换为 PHP 对象 - 因此您只需相应地访问它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句