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.
3 replies Latest Post - ‏2011-11-29T10:13:14Z by AntonAleksandrov
SystemAdmin
SystemAdmin
38 Posts
ACCEPTED ANSWER

Pinned topic Json form an Adapter

‏2011-11-28T17:40:41Z |
Hi I was wondering if we had access to the JSON object from inside the Adaptors.

I couldn't find it documented anywhere and the standard JSON Javascript object is undefined.
Was wondering if it's possible to access it through 'Packages'?

Ian
  • AntonAleksandrov
    AntonAleksandrov
    4 Posts
    ACCEPTED ANSWER

    Re: Json form an Adapter

    ‏2011-11-29T08:26:42Z  in response to SystemAdmin
    Hello Ian,

    As far as I know, the JSON object is not a standard JavaScript object, but something web browsers provide to simplify the developer's life (chrome/ff have it, IE don't), therefore it is not available in adapters out of the box.

    There are several ways to manipulate both JSON and XML in adapters, depends on what do you want to do - parse, generate, validate etc. Can you please elaborate more what are your requirements, maybe even provide a sample, so we can recommend a best fit solution?
  • SystemAdmin
    SystemAdmin
    38 Posts
    ACCEPTED ANSWER

    Re: Json form an Adapter

    ‏2011-11-29T09:20:06Z  in response to SystemAdmin
    At the moment I just want to dump some data to the logger so I can see what it looks like, but ideally I would like the adapter to do some of the data processing

    As the server is doing a lot of conversion to and from JSON I assumed that there would be some handy methods available.

    thanks,

    Ian
  • AntonAleksandrov
    AntonAleksandrov
    4 Posts
    ACCEPTED ANSWER

    Re: Json form an Adapter

    ‏2011-11-29T10:13:14Z  in response to SystemAdmin
    When you WL.Logger.debug(jsonObject) it will be dumped to the logger preserving its structure. WL.Logger.debug("my object is " + myObj) will not work due to a JS string-object concatenation restrictions, but WL.Logger.debug(obj) will output the object to the Worklight Console window.

    Also, if you have JSON as a string, you can convert it to object using JS's eval(), e.g. var myObj = eval(''); will produce an array with a single object in it. This is not optimal way to do it, but it will work.