Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-4876] Android - "hasOwnProperty" and JSON.parse incompatible

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2011-08-26T09:34:48.000+0000
Affected Version/sRelease 1.7.2
Fix Version/sSprint 2011-33, Release 1.8.0
ComponentsAndroid
LabelshasOwnProperty, json
ReporterPedro Enrique
AssigneeVikramjeet Singh
Created2011-08-03T09:44:58.000+0000
Updated2014-06-19T12:46:22.000+0000

Description

The function hasOwnProperty does not work in android when using a JSON object. Reason is that the JSON object ends up having double quotes on its properties making it a stringified object. For example, this does not work on Android:
var json = JSON.stringify({x: 1});

alert(JSON.parse(json).hasOwnProperty('x'));
If you where to alert the json alone, it would alert:
{ "x" : 1 }
This, instead, works fine:
alert( ({x: 1}).hasOwnProperty('x') );

Comments

  1. Karl Åström 2011-08-05

    Doublequoted keys in objects is perfectly legal in javascript and there is absolutely no reason why this should result in an object where the hasOwnProperty-method is 'undefined'.
  2. Karl Åström 2011-08-05

  3. Marshall Culpepper 2011-08-22

    To test this, you can simply run the json test suite in Drillbit, which has a new test that tests all kinds of different prototype functions for Object, String, Array, and Boolean on objects returned from JSON.parse.
  4. Natalie Huynh 2011-09-12

    Ran drillbit with version=1.8.0 timestamp=09/12/11 15:27 githash=8169a91 All test pass
  5. Sven Herzberg 2011-11-09

    How is this fixed? By changing the runtime to v8? Or is that fixed for anybody?

JSON Source