【发布时间】:2016-10-27 08:38:38
【问题描述】:
我正在尝试使用 php 和 curl 使用 REST API 制作一些页面。我可以在 PHP 上使用 curl 连接应用程序并以 JSON 格式获取所有值。但是,我无法解析我想要的值。
我使用这个 PHP 命令来解码 json 值;
$data = json_decode($response, true);
print_r($data);
当我使用这个命令时,我会得到这样的返回值;
数组 ( [链接] => 数组 ( ) [内容] => 数组 ( [0] => 数组 ( [@type] => ConsumerEnt [链接] => 数组 ([0] => 数组 ( [@type] => 链接 [rel] => GET: 请求 [href] => ………… ) => 数组 ...等
数组中有数组。我找不到如何解析我想要的值。您可以在以下 json 代码中看到我想要的值;
你知道这怎么可能吗?
比
You can see Decoded JSON by http://json.parser.online.fr/
{
"links": [],
"content": [
{
"@type": "ConsumerEnt",
"links": [
{
"@type": "link",
"rel": "GET: Request",
"href": "https://ip/url"
},
{
"@type": "link",
"rel": "POST:Request",
"href": "https://ip/url"
}
],
"entitledOrg": [
{
"tRef": "local",
"tLabel": "local",
"sRef": "768882f2-cf89-4cc8-92b7",
"sLabel": "USsB01"
}
],
"citems": "a0221dfd-00f9-4019-95ed",
"name": "NAME I WANT TO GET",
"description": "Basic",
"isNoteworthy": false,
"dateCreated": "2016-09-25T11:44:02.698Z",
"lastUpdatedDate": "2016-09-25T12:46:45.474Z",
"iconId": "a0221dfd-00f9-4019-95ed-a74faeb2e1b2",
"catalogItemTypeRef": {
"id": "com.company",
"label": "Compo"
},
"serviceRef": {
"id": "7c92b9a5-9dd5-4819-9320-4127b1e3009d",
"label": "NAME I WANT TO GET"
},
"outputResourceRef": {
"id": "composition.type",
"label": "test"
}
},
{
"@type": "ConsumerEnti",
"links": [
{
"@type": "link",
"rel": "GET: Request",
"href": "https://ip/url"
},
{
"@type": "link",
"rel": "POST:Request",
"href": "https://ip/url"
}
],
"entitledOrg": [
{
"tRef": "local",
"tLabel": "local",
"sRef": "768882f2-cf89-4cc8-92b7",
"sLabel": "astDF1"
}
],
"catalogItemId": "89b43bcb-4b23-4fc0-af26-66bd5c6bd1bc",
"name": "NAME I WANT TO GET",
"description": "RASDhFASel",
"isNoteworthy": false,
"dateCreated": "2016-10-27T07:55:03.243Z",
"lastUpdatedDate": "2016-10-27T07:56:00.754Z",
"iconId": "compos.png",
"catalogItemTypeRef": {
"id": "com.company",
"label": "Compo"
},
"serviceRef": {
"id": "7c92b9a5-9dd5-4819-9320-4127b1e3009d",
"label": "NAME I WANT TO GET"
},
"outputResourceRef": {
"id": "composition",
"label": "Dep"
}
}
],
"metadata": {
"size": 20,
"totalElements": 2,
"totalPages": 1,
"number": 1,
"offset": 0
}
}
【问题讨论】:
-
您实际需要什么类型的格式?
-
解析完美。您必须遍历数组以获得所需的结果
-
@AHJeebon 我需要文本格式。我需要在表格中列出产品。