{"_id":"55369c446fd3c40d00334964","project":"55369b3b6a63520d00ae6165","version":{"_id":"55369b3b6a63520d00ae6168","__v":1,"project":"55369b3b6a63520d00ae6165","createdAt":"2015-04-21T18:47:23.692Z","releaseDate":"2015-04-21T18:47:23.692Z","categories":["55369b3c6a63520d00ae6169"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"__v":0,"user":"55156c1dbc466623002afea2","category":{"_id":"55369b3c6a63520d00ae6169","pages":["55369b3c6a63520d00ae616b","55369c446fd3c40d00334964","55369cb24c3edb0d00877c82","5536a68d6a63520d00ae6177","5536a8ff245c930d007ed937"],"version":"55369b3b6a63520d00ae6168","project":"55369b3b6a63520d00ae6165","__v":5,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-04-21T18:47:24.200Z","from_sync":false,"order":0,"slug":"documentation","title":"Documentation"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-04-21T18:51:48.554Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n# Base URL for the API\\n$url  = 'http://api.nobelprize.org/v1/prize.json';\\n# List Nobel Prizes in Medicine from 1990 to 1994\\n$url .= '?category=medicine&year=1990&yearto=1994';\\n\\n# Retreieve the result from the API using CURL\\n$ch = curl_init();\\ncurl_setopt($ch, CURLOPT_URL,$url);\\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);\\n$string = curl_exec($ch);\\ncurl_close($ch);\\n\\n# Read the JSON output into an associative array\\n$result  = json_decode($string, true);\\n\\n# Find out how many years that are listed\\n$numyears = count($result['prizes']);\\n\\nfor ($i = 0; $i < $numyears; $i++) {\\n\\n# Print out the category and year\\n  $cat = $result['prizes'][$i]['category'];\\n  $year = $result['prizes'][$i]['year'];\\n  print \\\"<b>$cat $year</b><br>\\\\n\\\";\\n\\n# Find out how many laureates this category and year\\n  $numlaur = count($result['prizes'][$i]['laureates']);\\n\\n  for ($j = 0; $j < $numlaur; $j++) {\\n\\n#   Print out the names\\n    $firstname = $result['prizes'][$i]['laureates'][$j]['firstname'];\\n    $surname = $result['prizes'][$i]['laureates'][$j]['surname'];\\n    print \\\"$firstname $surname <br>\\\\n\\\";\\n\\n  }\\n  print \\\"<br>\\\\n\\\";\\n}\\n\\n?>\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]","excerpt":"Below are some code examples for the Nobel Prizes API","slug":"code-examples","type":"basic","title":"Code Examples"}

Code Examples

Below are some code examples for the Nobel Prizes API

[block:code] { "codes": [ { "code": "<?php\n\n# Base URL for the API\n$url = 'http://api.nobelprize.org/v1/prize.json';\n# List Nobel Prizes in Medicine from 1990 to 1994\n$url .= '?category=medicine&year=1990&yearto=1994';\n\n# Retreieve the result from the API using CURL\n$ch = curl_init();\ncurl_setopt($ch, CURLOPT_URL,$url);\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);\n$string = curl_exec($ch);\ncurl_close($ch);\n\n# Read the JSON output into an associative array\n$result = json_decode($string, true);\n\n# Find out how many years that are listed\n$numyears = count($result['prizes']);\n\nfor ($i = 0; $i < $numyears; $i++) {\n\n# Print out the category and year\n $cat = $result['prizes'][$i]['category'];\n $year = $result['prizes'][$i]['year'];\n print \"<b>$cat $year</b><br>\\n\";\n\n# Find out how many laureates this category and year\n $numlaur = count($result['prizes'][$i]['laureates']);\n\n for ($j = 0; $j < $numlaur; $j++) {\n\n# Print out the names\n $firstname = $result['prizes'][$i]['laureates'][$j]['firstname'];\n $surname = $result['prizes'][$i]['laureates'][$j]['surname'];\n print \"$firstname $surname <br>\\n\";\n\n }\n print \"<br>\\n\";\n}\n\n?>", "language": "php" } ] } [/block]