douxing1850 2014-11-03 08:40
浏览 477

如何从cURL结果中解析json?

I'm forced to use cURL to submit a form to obtain the results I need, unfortunately I've been haunted by the tedious task of having to parse the results that are in JSON.

My end-goal is to get this into a table that is legible and not some big block of text.

array(1) { ["SE"]=> array(4) { ["errors"]=> array(0) { } ["removedname"]=> string

That is just the start of the results of the page. My code so far is:

$h = curl_init();
curl_setopt($h, CURLOPT_URL, "http://mywebsite.com/index.php");
curl_setopt($h, CURLOPT_POST, true);
curl_setopt($h, CURLOPT_POSTFIELDS, array(
'user' => 'username',
'pass' => 'password',
'ph' => 'identifiyingInfo',
'vnum' => 'submit' # From the "Submit" button));
curl_setopt($h, CURLOPT_HEADER, false);
curl_setopt($h, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($h, CURLOPT_USERPWD, 'name:pass');
curl_setopt($h, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
curl_setopt($h, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($h, CURLOPT_SSL_VERIFYPEER, false);

$result = curl_exec($h);

curl_close($h);

var_dump(json_decode($result, true));

After adding the <pre></pre> tags, this became a lot more clear to me, but I'm still just not sure how to access the items in this array.

array(1) {
["SE"]=>
array(4) {
    ["errors"]=>
    array(0) {
    }
    ["billwith"]=>
    string(10) "removedInteger"
    ["bill_detail"]=>
    array(1) {
        ["bill_item"]=>
        array(48) {
          [0]=>
          array(7) {
            ["type1identifier_id"]=>
            string(5) "removed coded string "
            ["prod"]=>
            string(15) "removed string"
            ["charge"]=>
            string(4) "1.36"
            ["misc_date"]=>
            string(6) "063014"
            ["misc_date2"]=>
            string(6) "000000"
            ["notes"]=>
            string(0) ""
            ["color"]=>
            string(4) "hide"
          }
          [1]=>
          array(7) {
          ["type1identifier_id""]=>
          string(5) "CP024"
          ["prod"]=>
          string(15) "removed string "
          ["charge"]=>
          string(3) ".00"
          ["misc_date"]=>
          string(6) "063014"
          ["misc_date2"]=>
          string(6) "000000"
          ["notes"]=>
          string(0) ""
          ["color"]=>
          string(4) "hide"
  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用
    • ¥15 Web.config连不上数据库
    • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
    • ¥15 怎么配置广告联盟瀑布流
    • ¥15 Rstudio 保存代码闪退
    • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
    • ¥50 invest生境质量模块
    • ¥15 nhanes加权logistic回归,svyglm函数