gpt4 book ai didi

php - 从 url 解码 (PHP) 中获取属性

转载 作者:行者123 更新时间:2023-12-04 08:19:11 24 4
gpt4 key购买 nike

这是我获取数据的代码:

<?php

header('Content-Type: text/html; charset=UTF-8');
$request = file_get_contents('php://input');
//$req_dump = print_r( $request, true );
$fp = file_put_contents( 'request.log', urldecode(json_encode($request)));

?>
输出 :
domain_prefix = test & payload = {
"attributed_cost": "0.00",
"count": 50,
"id": "da674e25-5d9c-a8e2-1d5e-aa018b6cc1c3",
"outlet": {
"id": "3faf0608-91fa-11e3-a0f5-b8ca3a64f8f4",
"name": "West End Shop",
"tax_id": "e52b2846-e920-11e5-f98b-29c175501027",
"time_zone": "Australia/Brisbane"
},
"outlet_id": "3faf0608-91fa-11e3-a0f5-b8ca3a64f8f4",
"product": {
"active": true,
"attributed_cost": null,
"base_name": "Test Productss",
"button_order": null,
"categories": [],
"deleted_at": null,
"description": "",
"handle": "testproducts",
"id": "bfe919c4-6357-46c9-a333-d1db636446c5",
"name": "Test Productss",
"sku": "10203",
"source": "USER",
"source_id": null,
"source_variant_id": null,
"supply_price": "0.00",
"taxes": [{
"outlet_id": "3faf0608-91fa-11e3-a0f5-b8ca3a64f8f4",
"tax_id": "e52b2846-e920-11e5-f98b-29c175501027"
}],
"variant_options": [],
"variant_parent_id": null
},
"product_id": "bfe919c4-6357-46c9-a333-d1db636446c5",
"reorder_point": "0",
"restock_level": "0",
"version": 16073287694
} & retailer_id = 3 fa8309c - 91 fa - 11e3 - a0f5 - b8ca3a64f8f4 & type = inventory.update
我不确定如何从中获取“count”&“id”&“product_id”属性值。
我试过 parse_str但它没有用。
让我知道您对此的想法,如何从中获取数据?
谢谢

最佳答案

如果您的 $request 是这样的输出,那么您可以尝试
你可以试试

parse_str($request, $parse_request);
$payload = json_decode($parse_request["payload"], true);

$id = $payload["id"];
$count = $payload["count"];
$product_id = $payload["product"]["id"];

关于php - 从 url 解码 (PHP) 中获取属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65574012/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com