Jump to content

JSON


sepoto

Recommended Posts

The code below is from the Tumblr.com API manual. I do not know what to do with it? Do I put the code inside <script></script> tags? Why is there a URL? How is the URL used? Is there someplace on the web I can learn the basics of JSON?Thank you!

http://api.tumblr.com/v2/blog/david.tumblr.com/info?api_key={key}{   "meta": {	  "status": 200,	  "msg": "OK"   },   "response": {	  "blog": {		 "title": "David's Log",		 "posts": 3456,		 "name": "david",		 "url": "http:\/\/david.tumblr.com\/",		 "updated": 1308953007,		 "description": "<p><strong>Mr. Karp<\/strong> is tall and skinny, with			unflinching blue eyes a mop of brown hair.\r\n			He speaks incredibly fast and in complete paragraphs.</p>",		 "ask": true,		 "ask_anon": false,		 "likes": 12345	  }   }}

Link to comment
Share on other sites

I'm supposing that the URL is telling you that you need to load the content from a URL of that format. The code that follows the URL shown appears to be what would be loaded if you made a call to such URL.I believe this content is mean to be loaded by a server-side language, like PHP, since Javascript can't make cross-domain requests on all browsers.

Link to comment
Share on other sites

yup, looks like an example of a request URL that you need to make, and then an example of what the response would be. As mentioned you would have to do this on the server side, and then parse it for the data you need. On it's own JSON doesn't do anything. It's just a standard convention for transporting data (as a string) that can then be used in an application based on that applications needs.usually API documentation explains this. (the request/response method for interacting with their API at least)

Link to comment
Share on other sites

yup, looks like an example of a request URL that you need to make, and then an example of what the response would be. As mentioned you would have to do this on the server side, and then parse it for the data you need. On it's own JSON doesn't do anything. It's just a standard convention for transporting data (as a string) that can then be used in an application based on that applications needs.usually API documentation explains this. (the request/response method for interacting with their API at least)
I'm new to the API but I don't seem to see anything about how one would make a call to the URL listed in my first post from for example PHP. I do see that PHP has a few JSON functions but they seem to be oriented towards strings. That was all really great information but I have not really cracked the code yet. I guess I just need to keep asking questions. Thank you for the help out!
Link to comment
Share on other sites

look up cURL. and JSON is just passed as a string, and then a language like PHP has the ability to turn that into meaningful data (like an object or an array). Unfortunately, some API's assume a certain level of knowledge, through no fault of your own.as an example though, a basic curl example might be this:

<?php$request = 'http://api.tumblr.com/v2/blog/david.tumblr.com/info?api_key={key}'; //make sure you put your actual API key there (and remove the curly braces) $session = curl_init($request);curl_setopt($session, CURLOPT_RETURNTRANSFER, true);$response = curl_exec($session);$data = json_decode($response);var_dump($data);?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...