2018-08-02 19:21
浏览 305


i have searched a lot on google and here but im not getting any further with my problem. I am not a coder though I am trying to parse JSON to PHP Variables, but i get an empty response, where i want a table to be shown or at least any jsondata

Here is what my code looks like:

<!DOCTYPE html>

<h1>Available Agents </h1>

$url = 'https://url/livewebservice/imoscontactagentstate?Username=username&Pwd=password&Cmd=GetState&ResultType=JSON';
//  Initiate curl
$ch = curl_init ($url);
$data = json_encode ($data,true);

curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_HTTPHEADER, array (
' Content-Type: application/x-www-form-urlencoded ',
$result = curl_exec ($ch);
curl_close ($ch);
return $result;
var_dump(json_decode($result, true));
foreach ($result as $key => $value)
          echo '  <td><font  face="calibri"color="red">'.$value[type].'   </font></td><td><font  face="calibri"color="blue">'.$value[category].'   </font></td><td><font  face="calibri"color="green">'.$value[amount].'   </font></tr><tr>';

           echo "</tr></table>";



I am grateful for any hints

图片转代码服务由CSDN问答提供 功能建议

我在谷歌和这里搜索过很多但我没有进一步解决我的问题。 我不是编码器,虽然我试图解析JSON到PHP变量,但我得到一个空响应,我想要一个表显示或至少任何jsondata

这是什么 我的代码如下所示:

 &lt;!DOCTYPE html&gt; 
&lt; html&gt; 
&lt; body&gt; 
&lt; h1&gt;可用代理&lt; / h1&gt; \  n 
 $ url ='https:// url / livewebservice / imoscontactagentstate?用户名=用户名&amp; Pwd =密码&amp; Cmd = GetState&amp; ResultType = JSON'; 
 $ ch =  curl_init($ url); 
 $ data = json_encode($ data,true); 
 ncurl_setopt($ ch,CURLOPT_CUSTOMREQUEST,“POST”); 
curl_setopt($ ch,CURLOPT_POSTFIELDS,$ data); 
curl_setopt($  ch,CURLOPT_RETURNTRANSFER,true); 
curl_setopt($ ch,CURLOPT_HTTPHEADER,array(
'Content-Type:application / x-www-form-urlencoded',
'charset = utf-8')
); \  n $ result = curl_exec($ ch); 
curl_close($ ch); 
return $ result; 
var_dump(json_decode($ result,true)); 
 print_r($ result);  
Nacach($ result as $ key =&gt; $ value)
 echo'&lt; td&gt;&lt; font face =“calibri”color =“red”&gt;'。$ value [type]。'  &lt; / font&gt;&lt; / td&gt;&lt; td&gt;&lt; font face =“calibri”color =“blue”&gt;'。$ value [category]。'  &lt; / font&gt;&lt; / td&gt;&lt; td&gt;&lt; font face =“calibri”color =“green”&gt;'。$ value [amount]。'  &lt; / font&gt;&lt; / tr&gt;&lt; tr&gt;'; 
 echo“&lt; / tr&gt;&lt; / table&gt;”; 
&lt; / body&gt; 
&lt; / html&gt; 


  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • dongtao4319 2018-08-04 06:14

    The problem was solved my Username did not have the permission to access the data and we made minor changes to the code so it looks like this:

    $data = array(
    "UserName" => "Username",
    "Pwd" => "Password",
    "Cmd" => "GetAgentStateList",
    "ResultType" => "JSON",
     echo $url;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array( 
    "Content-Type: application/x-www-form-urlencoded", "charset=UTF-8",)); 
    $result = curl_exec($ch);
        throw new Exception(curl_error($ch));

    i hope this helps someone coming from google someday.

    解决 无用
    打赏 举报

相关推荐 更多相似问题