Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
13 replies Latest Post - ‏2013-02-28T14:07:41Z by SystemAdmin
SystemAdmin
SystemAdmin
13339 Posts
ACCEPTED ANSWER

Pinned topic 371548

‏2009-07-23T04:33:00Z |
371548
Updated on 2013-02-28T14:07:41Z at 2013-02-28T14:07:41Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    13339 Posts
    ACCEPTED ANSWER

    test

    ‏2009-10-02T20:19:59Z  in response to SystemAdmin
    The remark

    And this is its JSON representation:
    {symbol: 'IBM', price: 91.42}

    is incorrect. The example is not legal JSON. JSON objects must have strings for keys and strings must be double quoted, not single quoted. The official syntax for JSON is at http://json.org/. The correct JSON for the example is

    {"symbol": "IBM", "price": 91.42}
  • tot2ivn
    tot2ivn
    1 Post
    ACCEPTED ANSWER

    test

    ‏2009-12-29T18:42:54Z  in response to SystemAdmin
    Thanks for a really nice article on JSONP.
  • Exsuscito
    Exsuscito
    1 Post
    ACCEPTED ANSWER

    test

    ‏2010-03-19T18:23:10Z  in response to SystemAdmin
    Yes, however web browsers will parse that JSON anyway and let's be honest, JSON was designed for the web-browser. XML is a better choice because of the wide variety of support libraries available. Does JSON even support any kind of XPath or XQuery specification? I didn't think so.

    The Java-implementation of the JSON parser / serializer library at json.org leaves much to be desired. It is still a relatively immature implementation and we found we had to build a layer on-top of it as well as modify it to meet our requirements such as automatic POJO serialization and preserving order.

    But at the end of the day, web development is just more of a hobby that pays the bills from 9-5. Real developers are trying to shave cycles off of an OctTree implementation that indexes entities keyed with convex regions. Or devising an algorithm for discrete rasterization of cubic B-splines and applying it recursively to model river erosion... in multi-core.
  • Don-Joy
    Don-Joy
    2 Posts
    ACCEPTED ANSWER

    test

    ‏2010-06-24T13:30:37Z  in response to SystemAdmin
    You forgot one more important limitation of JSONP:

    Since what it's practically doing is to add a script tag to the document - it actually executes a GET request.
    As such, the maximum data the browser can send to the server is subject to the maximum length of a URL - which is 2K.

    It is noted that the HTTP cookies that the server sees are the cookies for his domain - means that since it's a cross-domain call, the presentation page in the browser and the server are accessing a different set of cookies, so if an authentication is required - it should be processed or passed to the cross-domain server as well.

    Beside from that - it's a great way.

    Have fun :)
  • Don-Joy
    Don-Joy
    2 Posts
    ACCEPTED ANSWER

    test

    ‏2010-06-24T13:36:53Z  in response to SystemAdmin
    Another remark to the first commenter:
    Quotes for key names are needed only for keys that contain special-characters.
    You can use all these characters for a key, and still not require quotes: A-Za-z0-8_$

    Many automated serializers do not bring that into consideration, and by design choose to wrap all keys with quotes - which is rather stupid for my part, especially when the response is prepared once and served many times from the cache. In this case I'd rather check for the need to wrap keys with quotes instead of wrapping all unconsciously.

    For example - mind the difference between the following two totally legal JSON expressions:

    {a:0,b:1,c:2,d:3}
    to
    {"a":0,"b":1,"c":2,"d":3}

    And when you serve a data-structure, its much more then 4 keys.
  • gofkurself
    gofkurself
    1 Post
    ACCEPTED ANSWER

    test

    ‏2010-06-29T04:56:08Z  in response to SystemAdmin
    This was useful and simple. Thanks.

    Exsuscito, my username applies to you and your comment.
  • prasu_5
    prasu_5
    1 Post
    ACCEPTED ANSWER

    test

    ‏2010-12-22T12:05:41Z  in response to SystemAdmin
    Can someone explain me how I can load remote url content into a div in my webpage using JSONP,
    thanks in advance
  • Johnywhy
    Johnywhy
    2 Posts
    ACCEPTED ANSWER

    test

    ‏2011-01-04T15:04:06Z  in response to SystemAdmin
    Beginner questions: hi, if you're willing to field very basic questions: "makes the hosting Web application vulnerable to a variety of attacks." --if code is executed on the client, doesn't it make the client vulnerable? How is the hosting app vulnerable? (or, do you mean the local JavaScript app?) thanks.
  • WebSiteBuildingCMS
    WebSiteBuildingCMS
    1 Post
    ACCEPTED ANSWER

    test

    ‏2011-04-08T09:24:14Z  in response to SystemAdmin
    but can you add examples with function that get the data back from the url
    regards
    <A href=http://web.2all.co.il>בניית אתרים</a>
  • micmath
    micmath
    1 Post
    ACCEPTED ANSWER

    test

    ‏2011-05-31T08:59:21Z  in response to SystemAdmin
    There are exactly 6 valid data types in JSON: quoted string, number, boolean, array, object, null. Therefore the following string is NOT a valid JSON representation: {symbol: 'IBM', price: 91.42}

    The commenter that states that using unquoted strings is "totally legal" is just plain wrong -- although some parsers may forgive this error, it is definitely not valid. The JSON spec is very clear about that.[1]. The above data, in order to be valid, should have been written: {"symbol": "IBM", "price": 91.42}

    [1] see RFC 4627: "A string begins and ends with quotation marks."
  • SystemAdmin
    SystemAdmin
    13339 Posts
    ACCEPTED ANSWER

    test

    ‏2011-10-01T00:01:48Z  in response to SystemAdmin
    Very good article. Detailing step by step and very precisely.

    Thanks,
    Vikas
  • ericfr
    ericfr
    1 Post
    ACCEPTED ANSWER

    test

    ‏2011-11-30T06:43:37Z  in response to SystemAdmin
    good article.

    I would just add the header needed in PHP when sending JSON data:
    header("Content-type: application/json");
  • SystemAdmin
    SystemAdmin
    13339 Posts
    ACCEPTED ANSWER

    test

    ‏2013-02-28T14:07:41Z  in response to SystemAdmin
    I've tried a few high ranking tutorials on this subject and they all confused me except yours. I get it now. Furthermore, your tute got me running some basic functions necessary for my project. Thank you.