亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 HTML 表單輸入使 json_decode 在 OOP 語句中工作

如何使用 HTML 表單輸入使 json_decode 在 OOP 語句中工作

PHP
慕婉清6462132 2021-10-15 16:06:37
我有一個簡單的 HTML 表單,使用 json_encode 將 PHP 變量(通過 value=)發送到文件,然后使用 json_decode 提取和回顯結果。我正在努力獲得正確的語法或方法來解碼 Opencart 所需的對象環境中的 json_decode。當我使用下面的程序方法時,它工作正常。我嘗試了各種語法更改,但它們返回錯誤,因此我認為語法不正確,或者我的方法無法通過這種方式完成。第一個代碼是返回正確結果的程序方法。第二個代碼是失敗的 OOP 方法。- (假設語法錯誤。Code Working:-  <form id="myForm" action="radio_result.php" method="post"   enctype="multipart/form-data">  <input type="radio" name="service" value="<?php echo   htmlentities(json_encode($service_onx));?>"> ONX//additional code excluded.radio_result.php // not all code shown  <?php       if(!empty($_POST['service'])) {    $service = json_decode($_POST['service'], true);    print_r($service);Code failing:-    <form id="myForm" action="index.php?route=checkout/checkout"     method="post" enctype="multipart/form-data">    <input type="radio" name="service" value="<?php echo     htmlentities(json_encode($service_onx));?>"> ONX    checkout.php // not all code shown    $this->session->data['service'] = (isset($this->request-    >post(json_decode(['service'])))) ? $this->request->post['service'] : "not_set";    $data['onx'] = $this->session->data['service'][0];    $data['eta'] = $this->session->data['service'][1];Error result:-Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead) in     C:\wamp64\www\catalog\controller\checkout\checkout.php on line 101I would like to get the json_decode working in the Opencart framework checkout.php so that I can use the reult further.
查看完整描述

2 回答

?
陪伴而非守候

TA貢獻1757條經驗 獲得超8個贊

有類似的問題。還通過在 base64 上編碼/解碼來解決它。base64_encode(json_encode($string))json_decode(base64_decode($string))


查看完整回答
反對 回復 2021-10-15
?
慕標琳琳

TA貢獻1830條經驗 獲得超9個贊

如果我理解正確,你需要一個對象?如果是這樣你可以先做

$service = json_decode($_POST['service'], true);

然后將此數組轉換為對象:

$serviceObject = (object) $service;

你會有一個對象。試試看。


查看完整回答
反對 回復 2021-10-15
  • 2 回答
  • 0 關注
  • 215 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號