如何查找和编辑自定义端点。在Wordpress Rest API中

时间:2019-06-27 10:40:23

标签: wordpress woocommerce wordpress-rest-api

我正在使用此WooCommerce Rest API来获取我的移动应用程序的产品。

我使用此API“ wp-json / wc / v3 / products / 344”来获得产品。

收到回复后,我得到了以下物体:

{ id: 5, name: test}

我在WooCommerce文件夹中找不到必须更改的位置。

如何将这些对象放入数组?

1 个答案:

答案 0 :(得分:0)

如果要在php中将JSON对象转换为数组,可以使用json_decode()这样的函数来实现。

$data = json_decode('{ "id": 5, "name": "test"}',true);
print_r($data);

输出

 Array ( [id] => 5 [name] => test )

但是

您的JSON响应{ id: 5, name: test}无效。有效的JSON字符串带有引号的键:

//fails
json_decode('{ id: 5, name: test}'); 

//return array Array ( [id] => 5 [name] => test )
json_decode('{ "id": 5, "name": "test"}', true); 

// returns an object stdClass Object ( [id] => 5 [name] => test)
json_decode('{ "id": 5, "name": "test"}');