[TIMOB-5499] JSON.parse returns [Ljava.lang.Object;@43fd4198 in Android
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Cannot Reproduce |
Resolution Date | 2011-10-31T15:56:53.000+0000 |
Affected Version/s | Release 1.7.2 |
Fix Version/s | Sprint 2011-44 |
Components | Android |
Labels | json, parse |
Reporter | Matt Stacy |
Assignee | Allen Yeung |
Created | 2011-08-23T11:29:45.000+0000 |
Updated | 2017-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.
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])").
This also affects property enumeration. Methods on the object are objects rather than functions. Ex:
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)
Matt [Ljava.lang.Object;@44cea438 is not an error, it is an object reference. Try the following:
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
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:
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 :( )
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
We switched to the Rhino-based JSON parser recently in master, we should verify this issue is also fixed by the move
Yes, this seems to be fixed in master build. Tnx
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.
Closing ticket as it has been over 5 years since the last update. Please open a new ticket if you have a problem.