Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-5499] JSON.parse returns [Ljava.lang.Object;@43fd4198 in Android

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionCannot Reproduce
Resolution Date2011-10-31T15:56:53.000+0000
Affected Version/sRelease 1.7.2
Fix Version/sSprint 2011-44
ComponentsAndroid
Labelsjson, parse
ReporterMatt Stacy
AssigneeAllen Yeung
Created2011-08-23T11:29:45.000+0000
Updated2017-03-31T17:24:13.000+0000

Description

In Android only this returns an error to the like of: [Ljava.lang.Object;@43fd4198
txt = '{"a": [5,6]}';
Ti.API.info("JSON.parse(txt).a[0]: " + JSON.parse(txt).a[0]);
Ti.API.info("JSON.parse(txt): " + JSON.parse(txt));
iOS processes with no error.

Comments

  1. Ivan Skugor 2011-08-24

    Yes, that's how object are printed and sometimes arrays also. It's totally useless. Although, you can use them without any problem (try: "Ti.API.info(txt.a[0])").
  2. Russell Munson 2011-09-14

    This also affects property enumeration. Methods on the object are objects rather than functions. Ex:
       (function(){
       var obj=JSON.parse('{"test":"yes"}'),
           key;
       
       Ti.UI.createWindow({
               backgroundColor : 'red'
       }).open();
       
       for(key in obj){
           if(obj.hasOwnProperty(key)){
               Ti.API.log("hasOwnProp",obj[key].hasOwnProperty('park'));
           }
       }
       })();
       
    09-14 13:59:50.783: ERROR/KrollContext(5042): (kroll$1: app://app.js) [338,718] ECMA Error evaluating source: TypeError: Cannot call property hasOwnProperty in object { 'test' : 'yes' }. It is not a function, it is "object". (file:///android_asset/Resources/app.js#12)
  3. Paul Dowsett 2011-09-23

    Matt [Ljava.lang.Object;@44cea438 is not an error, it is an object reference. Try the following:
       txt = '{"a": [5,6]}';
       Ti.API.info("JSON.parse(txt).a[0]: " + JSON.parse(txt).a[0]);
       Ti.API.info("typeof(JSON.parse(txt)): " + typeof(JSON.parse(txt)));
       
    Please note in the [Jira Ticket Checklist](http://wiki.appcelerator.org/display/guides/Contributing+to+Titanium#ContributingtoTitanium-Summary%3AJiraTicketChecklist) where it requires that you consult the community before raising a ticket. Thanks
  4. Ivan Skugor 2011-10-03

    Paul, that strange hash code may not be an error, but I think that's not the point. If you want to *debug* some variable, what is the point of outputting that strange hash code? Hash code/object reference id is totally useless when you are trying to *debug* values in some object. That's why, IMHO, debug output should contain string produced by "JSON.stringify" function. That output is useful for *debugging*. Also, see this:
       var txt = '{"a": [5,6]}';
       var obj = JSON.parse(txt);
       
       var jsObj = { a: [5,6] };
       
       Ti.API.info("parse " + obj.toString());
       Ti.API.info("native " + jsObj.toString());
       
       // parse {  'a' : [Ljava.lang.Object;@483515e8 }
       // native [object Object]
       
    The second output is the right one. "obj" contains object reference, but it is not printed as strange hash code, but it's property that contains an array is. It seems to me that is not consistent (and if I may presume, object returned by "JSON.parse" doesn't behave identical as native JS object because I found some more strange things regarding "JSON.parse" but I didn't try to isolate the issues because I have some more important things to do :( )
  5. Paul Dowsett 2011-10-12

    Matt Thanks for raising the ticket and making the case for this change in behavior. I have moved it to the main project, for the core team's consideration. Regards
  6. Marshall Culpepper 2011-10-13

    We switched to the Rhino-based JSON parser recently in master, we should verify this issue is also fixed by the move
  7. Ivan Skugor 2011-10-14

    Yes, this seems to be fixed in master build. Tnx
  8. Allen Yeung 2011-10-31

    Tested original test case, and I got: JSON.parse(txt).a[0]: 5 JSON.parse(txt): [object Object] It doesn't seem to return a hash string anymore.
  9. Lee Morris 2017-03-31

    Closing ticket as it has been over 5 years since the last update. Please open a new ticket if you have a problem.

JSON Source