1 / 15

JSON vs XML

JSON vs XML. Justin Zintak. Background. This project is a continuation of a project that I have been working on for a few months . It is an website for managing your online reputation called Repio . www.repio.com. Background.

dante
Télécharger la présentation

JSON vs XML

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JSON vs XML Justin Zintak

  2. Background • This project is a continuation of a project that I have been working on for a few months. • It is an website for managing your online reputation called Repio. • www.repio.com

  3. Background • We are currently using the Yahoo search API, which returns values in a JSON format. • In this case, the text is not “xml” in itself, but the process is the same; make a request, read the response, and parse the values.

  4. Purpose • For the purpose of this project I wanted to see if I could do the same thing, but with XML. • Throughout thecourse of my projectI noted some differences I found betweenJSON and XML. • There has been a lot of previous work distinguishing between XML and JSON.

  5. JSON • JSON, or JavaScript Object Notation, is a lightweight data-interchange format. • It is based on a subset of the JavaScript Programming Language. • JSON is built on two structures: • A collection of name/value pairs. In various languages, this is realized as an object, record, hash table, keyed list, or array. • An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.

  6. JSON vs XML • Primarily, I noticed that JSON and XML are really built for different purposes (obviously, but I got to see the differences first hand…). • XML is built for giving semantic meaning to text within documents. • JSON is built for data structures. • XML can be used to describe data structures, but when you need to deal with syntax for describing simple things like empty arrays, JSONis simply easier to work with.

  7. JSON vs XML • A strict JSON parser is not a lot of code. • I was able to write code returning JSON values in less than 10 lines (in CF and Java). • XML has a large set of extraction and transformation tools. • Stream and DOM (Document Object Model) parsers are widely available.

  8. Code for a JSON Response in CF jsonString is just a formatted string. “deserializeJson” converts a JSON string into CF data, such as a CF structure or array. item is set to the result of this process on the formatted jsonString. Loop through and save each of the results of the search.

  9. Code for a JSON Response in Java The String, jsonResponse is just a formatted string. There is a tool called “Gson()” that is able to convert the formatted string into a Java Structure. The YahooBossResult.class is a Java object that has properties that correspond to what is returnedby JSON. In this case, JSON is returning a deserialized version of the jsonResponse string into an object of type YahooBossResult.class Next, I loop through the results of the retrieved values. For each YahooBossRow called row, get the response and results. Then do something with the values. getResponsecode() == 200 is an HTTP Status-Code meaning everything is ‘ok’ As long as the structure of the class fits, the code should execute. If it doesn’t fit, it will throw a parse exception.

  10. Code for an XML Response This basically readies the search for the current user, in this case Steve Jobs. This is the get method for searching with the given parameters.

  11. Code for an XML Response Adds the results to the query to be displayed. Outputs and saves the results.

  12. Code for an XML Response XMLParse converts XML text into an XML document object. Loops through the search results (limited to 50), and sorts the data into a link, title, data, a description…etc

  13. Code for an XML Response Output and save the data

  14. Demo • I have the CF JSON code working and producing results.

  15. Questions?

More Related