does ajax need xml
play

Does Ajax need XML? The X in Ajax once stood for XML Now x is - PDF document

JSON Venkat Subramaniam svenkat@cs.uh.edu 1 Does Ajax need XML? The X in Ajax once stood for XML Now x is more like ? Whatever thats appropriate XML has its advantages and disadvantages Very expressive, but too noisy,


  1. JSON Venkat Subramaniam – svenkat@cs.uh.edu 1 Does Ajax need XML? • The X in Ajax once stood for XML • Now x is more like ? Whatever that’s appropriate • XML has its advantages and disadvantages – Very expressive, but too noisy, large, slow… Venkat Subramaniam – svenkat@cs.uh.edu 2

  2. JSON • JavaScript Object Notation • It is intended to be minimal • It is a textual notation of data • JavaScript is a superset of JSON • YAML is a superset of JSON – YAML decoder and JavaScript interpreter can be used as JSON decoder Venkat Subramaniam – svenkat@cs.uh.edu 3 What’s in JSON Source: http:www/json.org Venkat Subramaniam – svenkat@cs.uh.edu 4

  3. String • Strings – Any double quoted Unicode character – Double quote escaped using \ – Empty string represented by "" Source: http:www/json.org Venkat Subramaniam – svenkat@cs.uh.edu 5 Number • Numbers – Integer, real, scientific – Use null for invalid/ infinity Source: http:www/json.org Venkat Subramaniam – svenkat@cs.uh.edu 6

  4. Object • Objects: More of a hashmap notation – { "keyname": JSONValue, "keyname": JSONValue,… } – JSONValue may be any of the JSON value types including other objects Source: http:www/json.org Venkat Subramaniam – svenkat@cs.uh.edu 7 Arrays • Arrays – Sequence of values – [ JSONValue, JSONValue, JSONValue, … ] – Index is decided by implementation (like Java can use 0, VB can use 1, JSON doesn’t care) – JSONValue may be any JSON value type including objects and arrays Source: http:www/json.org Venkat Subramaniam – svenkat@cs.uh.edu 8

  5. Using JSON to Populate a Page Venkat Subramaniam – svenkat@cs.uh.edu 9 Concerns with eval • eval sends the JSON text (or any text) to the Java compiler • May not be safe • Use only if trusted source • What’s the alternative • parseJSON only parses JSON text Venkat Subramaniam – svenkat@cs.uh.edu 10

  6. parseJSON • Available from http: / / www.json.org/ json.js • Parses only JSON text and is fast Venkat Subramaniam – svenkat@cs.uh.edu 11 Convert to JSON • toJSONString() converts an object to JSON Venkat Subramaniam – svenkat@cs.uh.edu 12

  7. More Convenience • More convenient processing functions are sprouting up • There is also proposal for JSONRequest object to be standardized by browsers – http: / / json.org/ JSONRequest.html Venkat Subramaniam – svenkat@cs.uh.edu 13

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend