Tech Support Websites

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Tuesday, 17 July 2012

HOW TO work with a JSON/JSONP feed locally

Posted on 07:34 by Unknown

When you're working with a JSONP feed  like the one returned by Twitter Search API or Google News, the different results that show up each time may distract you from the functionality that you're building. You can instead work with a copy of the JSON resultset locally and hook up the code to the actual JSONP feed when you're done.

A JSONP feed is just JSON-formatted response wrapped in a function call. You can grab the JSONP content generated by an API by going to the Network Tab within Developer Tools (F12 keyboard shortcut) of Chrome or IE or Firebug within Firefox.

When a JSONP feed is called through jQuery, it will look something like this -
jQuery17109422175763174891_1337695981767({json})

To work with the dynamically generated JSON, we need the content within the brackets - {json}

Save that content within a text file & give it some name & a ".js" extension. To use the JSON content locally, specify the file name as the first parameter to the $.getJSON method -

$(document).ready(function(){
    $.getJSON('tsearch.js', function(response){
      for(var i=0;i<response.results.length; i++){
      $('#tweets').append("<li>" + response.results[i].text + "</li>");
    }});
});

The above example refers to  JSON returned by Twitter Search API.

Also see:

HOW TO show expanded form of shortened URL within a tweet using Twitter API 
HOW TO convert a RSS feeed to a JSONP feed on the fly

Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in APIs, Javascript, jQuery, JSON | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Windows 8 keyboard shortcuts
    Win + X   - context menu to access common features like Control Panel, Task Manager, File Explorer, Programs & Features, Run, Search etc...
  • My 30-day personal project - watch 100 hours of Pluralsight videos
    Inspired by Matt Cutts' 30-day challenges , I plan to watch 100 hours of Pluralsight online videos to get up-to-date with current ...
  • Archive tweets & favorites with Google Reader
    There are numerous ways to archive tweets but rather than use yet another tool, I prefer using Google Reader to preserve the tweets I mark ...
  • Azure in Pictures - overview of Windows Azure Features, Services and Common Uses
    Download the Windows Azure Poster in PDF format (1.1MB)
  • Dashboard-like info with Browser tabs, Windows 7 Taskbar tabs
    Browser tabs & Windows 7 Taskbar tabs are turning self-aware.  This is how my browser looked the other day: I had the summary of all tha...
  • What is the difference between Browser Mode & Document Mode in IE
    If you're a web developer and your job actively involves building web pages that work the same in all browsers including the last three ...
  • 10 ways to make laptop battery last longer
    Paraphrased from a Right Choice magazine article with my own opinions: Keep the brightness of the screen as low as possible. If portability ...
  • India ranks fourth in Internet usage
    Deepak Shenoy informs that as per Telecom Regulatory Authority of India (TRAI) data, India has nearly 10 million Broadband connections in ...
  • HOW TO let Google watch over your web activity
    When we get onto the Internet, we trade our privacy for convenience. Everyone from marketers, ISPs to Governments can watch our activities o...
  • The Glorious History of Internet Explorer
    Love it or hate it, you will have to appreciate IE’s staying power. Having been around for 16 years, it is still the browser market leader ....

Categories

  • AJAX
  • Android
  • APIs
  • App
  • ASP
  • ASP.NET
  • ASP.NET-MVC
  • Azure
  • Azure SQL Database
  • AzureInPictures
  • Bing
  • Book Review
  • Bookmarklet
  • Browsers
  • C#
  • chart
  • Chrome
  • Cloud
  • CSS
  • CSS3
  • DidYouKnow
  • E-Commerce
  • Excel
  • FB
  • Fiddler
  • Firefox
  • Gadgets
  • GeoLocation
  • GMail
  • Google
  • Google Docs
  • Google Reader
  • Health
  • Hotmail
  • HOWTO
  • HTML
  • HTML/CSS
  • HTML5
  • Humor
  • Hyderabad
  • IE
  • IIS
  • India
  • Internet
  • IT
  • Javascript
  • jQuery
  • JSON
  • JSONP
  • Laptop
  • Learning Resources
  • Lists
  • Map
  • Metrics
  • Microsoft
  • miscellaneous
  • Mobile
  • NAPA
  • Office365
  • Opera
  • PDF
  • Performance
  • Personal
  • PHP
  • PM
  • PowerShell
  • Privacy
  • Programming
  • Rant
  • Safari
  • Science
  • Search Engines
  • SearchEngines
  • Security
  • SEO
  • Sharepoint
  • SharePoint2013
  • Silverlight
  • Software Engineering
  • Solutions
  • SQL Azure
  • SQL Server
  • TFS
  • Tip
  • Tips
  • Tools
  • Tools/Utilities
  • Trivia
  • TWIL
  • Twitter
  • UX
  • VM
  • VS.NET
  • VS2010
  • VS2012
  • WCF
  • WebApps
  • Websites
  • WF
  • Windows Phone
  • Windows7
  • Windows8
  • Word
  • WP7
  • WPF

Blog Archive

  • ►  2013 (112)
    • ►  October (16)
    • ►  September (14)
    • ►  August (8)
    • ►  July (8)
    • ►  June (13)
    • ►  May (12)
    • ►  April (12)
    • ►  March (8)
    • ►  February (15)
    • ►  January (6)
  • ▼  2012 (127)
    • ►  December (11)
    • ►  November (14)
    • ►  October (13)
    • ►  September (14)
    • ►  August (16)
    • ▼  July (16)
      • Book Review: SharePoint 2010 Plain & Simple
      • HOW TO make columns in an ASP.NET GridView sortabl...
      • The first 20 employees of Google
      • Power Searching with Google (and Bing)
      • What is the difference between Browser Mode & Docu...
      • HOW TO find what movies two film personalities hav...
      • Google institutes MVP/GDE award to recognize devel...
      • HOW TO work with a JSON/JSONP feed locally
      • Building a dynamic jQuery Selector for an element ...
      • NOBR - a non-standard HTML tag that all browsers s...
      • HOW TO convert HTML content to plain text - with E...
      • Websites that track traffic in Indian cities
      • Web Apps Watch - 2
      • NLPCaptcha - yet another CAPTCHA implementation
      • Free APIs for HTML5 Geolocation apps, mashups
      • HOW TO read long text messages on the Samsung Omni...
    • ►  June (6)
    • ►  May (5)
    • ►  April (11)
    • ►  March (12)
    • ►  February (7)
    • ►  January (2)
  • ►  2011 (98)
    • ►  December (5)
    • ►  November (2)
    • ►  October (5)
    • ►  September (7)
    • ►  August (7)
    • ►  July (15)
    • ►  June (10)
    • ►  May (7)
    • ►  April (8)
    • ►  March (10)
    • ►  February (11)
    • ►  January (11)
  • ►  2010 (163)
    • ►  December (14)
    • ►  November (19)
    • ►  October (19)
    • ►  September (15)
    • ►  August (18)
    • ►  July (17)
    • ►  June (20)
    • ►  May (17)
    • ►  April (19)
    • ►  March (5)
Powered by Blogger.

About Me

Unknown
View my complete profile