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 outlook无法配置成功
    • ¥15 Pwm双极模式H桥驱动控制电机
    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换