从GND数据库获取CURL JSON响应php数组的特定值

时间:2018-09-14 15:14:49

标签: php json curl

我搞砸了使用JSON的GND API,这似乎使提取特定数据变得更加困难(至少对我而言)。

我尝试从GND网站获取单个值。我已经有代码可以接收整个数据条目。

<?php

            // Setting the HTTP Request Headers
                $User_Agent = 'Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0';

                $request_headers = array();
                $request_headers[] = 'Accept: application/json';
            $request_headers[] = 'Content-Length: ' . strlen($data_string);


            //PHP Infos anzeigen lassen
            //phpinfo();

        $id = $_POST["id"];             
                // URL to fetch
                $url = "http://hub.culturegraph.org/entityfacts/$id";
                $curl = curl_init($url);
                curl_setopt($curl, CURLOPT_URL, $url);
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($curl, CURLOPT_HEADER, false);
                $json = curl_exec($curl);

                $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
                curl_close($curl);


                // Performing the HTTP request
                //  Initiate curl
              $ch = curl_init($url);
              // Set the url
                curl_setopt($curl, CURLOPT_URL, $url);
                // Will return the response, if false it print the response
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($curl, CURLOPT_HEADER, false);
                curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
                curl_setopt($curl, CURLOPT_POST, true);
                curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
                curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
                // Execute
                $result = curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any).
                // Closing
        curl_close($ch);    

        curl_error
?>

但是我只想从数据条目中获取特定的值,例如“ @type“ person”variantName。Json-Code的一部分如下所示:

@context    "http://hub.culturegraph.org/entityfacts/context/v1/entityfacts.jsonld"
@id "http://d-nb.info/gnd/118640445"
preferredName   "Leonardo, da Vinci"
surname "Leonardo, da Vinci"
describedBy 
valid   "2018-09-14T10:46:49+0200"
license "https://creativecommons.org/publicdomain/zero/1.0/"
@id "http://hub.culturegraph.org/entityfacts/118640445"
@type   "person"
variantName 
0   "Leonard, de Vinci"
1   "Léonard, de Vinci"
2   "Léonard"
3   "Leonardus, Vincius"
4   "Lionardo, da Vinci"
5   "Lionardo"
6   "Leonardo"
7   "Leonardo da Vinči"
8   "Leonardo de Vinci"
9   "Leonard da Vinci"
10  "Léonard de Vinci"
11  "Leonhard von Vinci"
12  "Lionardo da Vinci"
13  "Lionardo de Vinci"
14  "Leonard, da Vinci"
15  "Reonarŭdo, ta-Pinch'i-ŭi"
16  "Leonardo, da Vinči"
17  "Leonardo, de Vinci"
18  "Leonarnto, sta Bintsi"
19  "Leonardo, da Vinchi"
20  "Leonaďo, da Vinchi"
21  "Leonardo da Vinci"
22  "Leonardo Da Vinci"
23  "Leonardo da Vinci, Maler, Architekt, Naturforscher"
24  "Leonardo da Vinci, Peintre, Naturaliste, Architecte"
25  "Leonardo da Vinci, Painter, Architect, Naturalist"
26  "Léonard, de Vinci, Maler, Architekt, Naturforscher"
27  "Léonard, de Vinci, Peintre, Naturaliste, Architecte"
28  "Léonard, de Vinci, Painter, Architect, Naturalist"
29  "Léonard de Vinci, Maler, Architekt, Naturforscher"
30  "Léonard de Vinci, Peintre, Naturaliste, Architecte"
31  "Léonard de Vinci, Painter, Architect, Naturalist"
32  "Lionardo da Vinci, Maler, Architekt, Naturforscher"
33  "Lionardo da Vinci, Peintre, Naturaliste, Architecte"
34  "Lionardo da Vinci, Painter, Architect, Naturalist"
35  "Lionardo, da Vinci, Maler, Architekt, Naturforscher"
36  "Lionardo, da Vinci, Peintre, Naturaliste, Architecte"
37  "Lionardo, da Vinci, Painter, Architect, Naturalist"
38  "Leonardo, Maler, Architekt, Naturforscher"
39  "Leonardo, Peintre, Naturaliste, Architecte"
40  "Leonardo, Painter, Architect, Naturalist"
41  "Leonardo Da Vinci, Maler, Architekt, Naturforscher"
42  "Leonardo, da Vinci, Painter, Architect, Naturalist"
43  "Leonardo, da Vinci, Maler, Architekt, Naturforscher"
44  "Leonardo, da Vinci, Peintre, Naturaliste, Architecte"
45  "Leonardo DaVinci"
dateOfBirth "15. April 1452"
dateOfDeath "2. Mai 1519"

我该怎么做?

0 个答案:

没有答案