如何用它们的对象值回显这个json数据?

时间:2017-07-31 08:36:06

标签: php json

{  
   "Content":{  
      "App":null,
      "CompleteFile":null,
      "CompleteFile1":null,
      "DeliveryCharge":"hdDeliveryCharge",
      "ErrorCode":"ErrorCode",
      "ErrorText":"ErrorText",
      "HomeAddress":"hdHomeAddress",
      "IntimationStatus":null,
      "LabOrderNumber":"1",
      "LoginType":null,
      "OrderStatus":null,
      "PaymentCompleteUrl":"",
      "PaymentStartUrl":"",
      "ProfileFile":"",
      "Quuid":null,
      "StoreCount":null,
      "StoreSrNo":null,
      "TransactionId":"TransactionId",
      "UserLat":null,
      "UserLong":null,
      "VersionNumber":null,
      "hdValue":"hdValue"
   },
   "FtpDetail":{  
      "Folder":"FujiFilmIMP",
      "IPAddress":"66.7.149.132",
      "Password":"ox@2017DG",
      "Port":"21",
      "UserName":"oxstudio"
   },
   "Head":{  
      "ErrorCode":"1",
      "ErrorText":"Login success",
      "ErrorValue":null
   },
   "ShippingDetails":null,
   "StoreDetails":null,
   "UserDetails":{  
      "Address":"mira road",
      "City":"mumbai",
      "CountryId":"356",
      "Email":"mamender@dgflick.in",
      "Mobile":"8626065289",
      "Name":"Mamender",
      "Password":"123",
      "PinCode":"400001",
      "StateId":"1575",
      "UserMasterId":"7462"
   }
 }

2 个答案:

答案 0 :(得分:-1)

您需要将其转换为数组,然后才能遍历数组。

要转换为数组,请假设您的json位于名为alternate?

的变量中
$json

然后你可以随心所欲地做任何你喜欢的事情。

答案 1 :(得分:-1)

工作示例!

<?php

$data='{  
   "Content":{  
      "App":null,
      "CompleteFile":null,
      "CompleteFile1":null,
      "DeliveryCharge":"hdDeliveryCharge",
      "ErrorCode":"ErrorCode",
      "ErrorText":"ErrorText",
      "HomeAddress":"hdHomeAddress",
      "IntimationStatus":null,
      "LabOrderNumber":"1",
      "LoginType":null,
      "OrderStatus":null,
      "PaymentCompleteUrl":"",
      "PaymentStartUrl":"",
      "ProfileFile":"",
      "Quuid":null,
      "StoreCount":null,
      "StoreSrNo":null,
      "TransactionId":"TransactionId",
      "UserLat":null,
      "UserLong":null,
      "VersionNumber":null,
      "hdValue":"hdValue"
    },
   "FtpDetail":{  
      "Folder":"FujiFilmIMP",
      "IPAddress":"66.7.149.132",
      "Password":"ox@2017DG",
      "Port":"21",
      "UserName":"oxstudio"
   },
  "Head":{  
     "ErrorCode":"1",
     "ErrorText":"Login success",
     "ErrorValue":null
   },
  "ShippingDetails":null,
  "StoreDetails":null,
  "UserDetails":{  
      "Address":"mira road",
      "City":"mumbai",
      "CountryId":"356",
      "Email":"mamender@dgflick.in",
      "Mobile":"8626065289",
      "Name":"Mamender",
      "Password":"123",
      "PinCode":"400001",
      "StateId":"1575",
      "UserMasterId":"7462"
   }
 }';

$dataDecoded = json_decode($data);

?>

<pre>
    <!-- View Ftp detail-->
    <?php print_r($dataDecoded->FtpDetail);?>

    <!--View User Ftp detail Ip adress, will display: 66.7.149.132-->
    <?php echo $dataDecoded->FtpDetail->IPAddress ?>

    <!--View User UserDeatails Email, will display:mamender@dgflick.in-->
    <?php echo $dataDecoded->UserDetails->Email ?>
</pre>