json傳回值帶函數名,PHP裡如何回調呢

來源:互聯網
上載者:User
json傳回值帶函數名,PHP裡怎麼回調呢?
本帖最後由 zlbpolly 於 2014-08-26 21:22:37 編輯

以下內容是抓取到的,現在我只能截取字串,把函數名過濾掉,再按json格式取值。
有沒有辦法直接回呼函數呢?

jsonp3({ "status": 200, "ercode": 0});

------解決方案--------------------
沒有好辦法,因為 php 尚不支援把對象寫作 {}
不知道你是怎樣把函數名過濾掉的
php5.4及以下可寫作
$s  = 'jsonp3({ "status": 200, "ercode": 0})';
preg_replace('/^\w+?\((.+)\)$/ise', 'count($r=json_decode("$1"))', $s);
print_r($r);
php5.3及以上可寫作
$s  = 'jsonp3({ "status": 200, "ercode": 0})';
preg_replace_callback('/^\w+?\((.+)\)$/is', function($m) use (&$r) { $r = json_decode($m[1]); }, $s);
print_r($r);
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.