Data Formats: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
Line 1: Line 1:
There are several formats commonly used to transfer data to and from Web Services.
= JSON =
= JSON =
* JSON (JavaScript Object Notation) is the simplest and most commonly used.
* It is simply a JavaScript object turned into a string.
* It is the same as a BASIC object turned into a string.
Here is what it looks like in expanded form:
<pre>
<pre>
{
{
Line 22: Line 30:
     ]
     ]
}
}
</pre>
AppStudio has a couple of handy statements for manipulating JSON strings:
<pre>
  myObject = JSON.Parse(jsonString)    'Convert a JSON string to an object
  jsonString = JSON.Stringify(myObject) 'Convert an object into a JSON string
</pre>
</pre>



Revision as of 18:13, 10 December 2013

There are several formats commonly used to transfer data to and from Web Services.

JSON

  • JSON (JavaScript Object Notation) is the simplest and most commonly used.
  • It is simply a JavaScript object turned into a string.
  • It is the same as a BASIC object turned into a string.

Here is what it looks like in expanded form:

{
    "firstName": "John",
    "lastName": "Smith",
    "age": 25,
    "address": {
        "streetAddress": "21 2nd Street",
        "city": "New York",
        "state": "NY",
        "postalCode": "10021"
    },
    "phoneNumber": [
        {
            "type": "home",
            "number": "212 555-1234"
        },
        {
            "type": "fax",
            "number": "646 555-4567"
        }
    ]
}

AppStudio has a couple of handy statements for manipulating JSON strings:

  myObject = JSON.Parse(jsonString)     'Convert a JSON string to an object

  jsonString = JSON.Stringify(myObject) 'Convert an object into a JSON string

JSONP

functionCall({
    "firstName": "John",
    "lastName": "Smith",
    "age": 25,
    "address": {
        "streetAddress": "21 2nd Street",
        "city": "New York",
        "state": "NY",
        "postalCode": "10021"
    },
    "phoneNumber": [
        {
            "type": "home",
            "number": "212 555-1234"
        },
        {
            "type": "fax",
            "number": "646 555-4567"
        }
    ]
  }
)

XML

<pre>
<person>
  <firstName>John</firstName>
  <lastName>Smith</lastName>
  <age>25</age>
  <address>
    <streetAddress>21 2nd Street</streetAddress>
    <city>New York</city>
    <state>NY</state>
    <postalCode>10021</postalCode>
  </address>
  <phoneNumbers>
    <phoneNumber type="home">212 555-1234</phoneNumber>
    <phoneNumber type="fax">646 555-4567</phoneNumber>
  </phoneNumbers>
</person>
<person firstName="John" lastName="Smith" age="25">
  <address streetAddress="21 2nd Street" city="New York" state="NY" postalCode="10021" />
  <phoneNumbers>
     <phoneNumber type="home" number="212 555-1234"/>
     <phoneNumber type="fax"  number="646 555-4567"/>
  </phoneNumbers>
</person>