loadjson()
Creates a JSON object based on the text retrieved from the
supplied location. The function lets you retrieve content
from an JSON enabled server using a standard HTTP request. Popular
content management systems, like WordPress (requires JSON API
plug-in) and Drupal provide a JSON service/API to retrieve
content.
Loadjson() is cached per batch run (based on the URL)
in print/email.
This online JSON viewer is handy to debug JSON data: http://jsonviewer.stack.hu
loadjson(location)
Loads json data from a remote location.
location
String; the supplied location should
be either a URL or a relative file path.
Examples
This sample script retrieves JSON data from a . var localJSON = loadjson('/jsonsnippet.html'); if(localJSON.post){ results.html("<h3>" + localJSON.post.title + "</h3><p>" + localJSON.post.modified + "</p>");
}
This script retrieves a post from a WordPress
site. var wpPost = loadjson('http://192.168.101.58/2013/06/leave-the-third-dimension-behind-and-focus-on-real-printing-innovation/?json=1'); if(wpPost.post){ results.html("<h1>" + wpPost.post.title + "</h1>"
+ wpPost.post.content); }
This script retrieves multiple posts from a WordPress
site. var numPosts = 3; var wpPost = ''; var wpRecentPosts = loadjson('http://192.168.101.58/?json=get_recent_posts&count=' + numPosts); if(wpRecentPosts.posts){ for (var i = 0; i < numPosts ; i++) { wpPost += "<p>" + wpRecentPosts.posts[i].title + "</p>"; } } results.after(wpPost)
|