Confused about very basics of JSON - Some APIs make me download a file, others show the json
Tonight I want to make a request to the topsy.com API, which returns JSON and render that as HTML.
I've never done anything with json before since it's impossible to read in the browser, but that's the only format Topsy returns, so I'm trying to learn what I can. I have a very basic question:
- Why do some APIs make me download a json file when I ping them in the browser while others show me a white screen with a bunch of json text on them?
Compare the result of clicking this URL:
http://otter.topsy.com/se开发者_如何学Carch.json?q=site:wired.com&window=d7
with this one:
http://www.twitter.com/statuses/user_timeline/nirmalpatel.json?callback=showTweets&count=20
What's the difference?
I ask because I found some js that will render json as HTML
http://nirmalpatel.com/json2posh/
In his example, he makes a call to Twitter's API that returns JSON, runs that through his javascript, and then it renders HTML on the page.
I'm trying to figure out how to change his code to make it work for the Topsy API call.
Here's the API request I want to render as HTML
http://otter.topsy.com/search.json?q=site:wired.com&window=d7
I've added his json2posh.js to my site, so that's "live" so to speak.
And I've added the callback script and the DOM element where the HTML is supposed to be rendered.
What I can't figure out is how I'm supposed to call the Topsy API and then feed the response into this guy's code.
I'm thinking it might be explained by whatever reason those two URLS show me such different results.
if the site returns json as content-type: text/plain
you will see it in the browser.
if the site returns json as content-type: text/json
you will likely get a save file dialog.
if you are using IE, you can force it to show json as text: see How can I convince IE to simply display application/json rather than offer to download it?
firefox has several JSON viewer addons but I am not familiar with them.
精彩评论