Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Debugging object in JSON notation

I've been trying to find a good way to debug in Titanium Mobile, but ran into some issues.

Whenever I debug my object, all I get is "object" and the object Type (e.g. [object TiUITableView]). I would however like to see its contents in a JSON format. If I try:
Titanium.API.debug(JSON.stringify(items));

All I get is an empty object ({}) while I'm sure something's in there. (I have also tried it with Titanium.UI.currentWindow which also returns {})

Is there any way to achieve this?

Eternal gratitude to he who relieves me from this agony…

— asked July 5th 2010 by HOWEST *
  • console
  • debug
  • info
  • ipad
  • iphone
  • json
  • log
  • mobile
  • stringify
0 Comments

3 Answers

  • Accepted Answer

    Ok - I've revisited the code and pushed the envelope a little harder.

    You can find the result - http://gist.github.com/465256

    An example of using it is:

    // I've tried to catch every error but you never know :)
    try {
      dumpObj2(items, true, true);
    } catch (e) {
      // Wussup doc?
      debug(e.message);    
    }
    

    As you'll see from the gist

    • the first arg is what you want to debug
    • the second arg is a flag (true|false) saying if you want deep information or not
    • the last arg is a flag (true|false) saying if you want funcs included
    — answered July 6th 2010 by David Ashwood
    permalink
    1 Comment
    • I tested this on Android with the tableview and it worked.
      Let me know if there's any issues with it :)

      — commented July 6th 2010 by David Ashwood
  • Update2: see this gist instead: http://gist.github.com/465256

    — answered July 5th 2010 by David Ashwood
    permalink
    2 Comments
    • I would love to see more of these helper functions that people find useful. is there a collection anywhere on github?

      — commented July 5th 2010 by max ogden
    • Not yet max but it's a good idea :)

      — commented July 6th 2010 by David Ashwood
  • Unfortunately I cannot get this working with ANY Titanium object. If I make my own object, it works fine, but any Titanium object does not get into the for loop. It's as if there are no properties.

    I have tried the following:

    var tableItems = [{title: 'Pagina 1'},{title: 'Pagina 2'},{title: 'Pagina 3'}];

    var items = Titanium.UI.createTableView(
    { data:tableItems,
    width: 200,
    position: 'absolute',
    rowHeight: 100,
    rowCount: tableItems.length
    }
    );

    dumpObject(items);
    

    But gives me no result whatsoever… (and yes it does call the function :-) )

    — answered July 6th 2010 by HOWEST *
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.