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

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

如何使用cURL獲取jSON數據并解碼數據?

如何使用cURL獲取jSON數據并解碼數據?

阿波羅的戰車 2019-08-12 11:14:20
如何使用cURL獲取jSON數據并解碼數據?所以我有一個返回jSON對象的鏈接,我需要將它解碼并放入PHP中的變量中。網址api.php?action=getThreads&hash=123fajwersa&node_id=4&order_by=post_date&order=desc&limit=1&grab_content&content_limit=1這是它返回的對象{     "count": 1,     "threads": {         "38752": {             "thread_id": 38752,             "node_id": 4,             "title": "The ShadyCraft Beta Launch!",             "reply_count": 45,             "view_count": 946,             "user_id": 2,             "username": "Shady",             "post_date": 1366956695,             "sticky": 0,             "discussion_state": "visible",             "discussion_open": 1,             "discussion_type": "",             "first_post_id": 226167,             "first_post_likes": 7,             "last_post_date": 1369094302,             "last_post_id": 228226,             "last_post_user_id": 2,             "last_post_username": "Shady",             "prefix_id": 19,             "tinhte_xentag_tags": "a:4:{i:0;s:9:\"minecraft\";i:2;s:4:\"news\";i:3;s:14:\"private server\";i:1;s:10:\"shadycraft\";}",             "content": {                 "count": 1,                 "content": {                     "226167": {                         "post_id": 226167,                         "thread_id": 38752,                         "user_id": 2,                         "username": "Shady",                    }                 }             }         }如果元素具有作為數組本身的[threads]元素,那么它就是元素。我怎么得到,也許[thread_id]元素的價值?
查看完整描述

3 回答

?
qq_遁去的一_1

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

我想這個會回答你的問題:P

$url="https://.../api.php?action=getThreads&hash=123fajwersa&node_id=4&order_by=post_date&order=?desc&limit=1&grab_content&content_limit=1";

運用 cURL

//  Initiate curl$ch = curl_init();// Will return the response, if false it print the responsecurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);// Set the urlcurl_setopt($ch, CURLOPT_URL,$url);// Execute$result=curl_exec($ch);// Closingcurl_close($ch);// Will dump a beauty json :3var_dump(json_decode($result, true));

運用 file_get_contents

$result = file_get_contents($url);// Will dump a beauty json :3var_dump(json_decode($result, true));

訪問

$array["threads"][13/* thread id */]["title"/* thread key */]

$array["threads"][13/* thread id */]["content"/* thread key */]["content"][23/* post id */]["message" /* content key */];


查看完整回答
反對 回復 2019-08-12
  • 3 回答
  • 0 關注
  • 1498 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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