Skip to content

JSON.stringify(arrayOfParseObjects) throws TypeError: seen.indexOf is not a function #435

Closed
@superbigsoft

Description

@superbigsoft

I'm having TypeError: seen.indexOf is not a function in an CordovaApp running on iOS 9.3. (The error does not happen on Chrome/Safari or iOS 10)
=> Please let me know if the work-around below does not cause any side effect. Thanks all.

I have following Parse Object structures:

  • User : 1 entry
  • House { owner: Pointer }: 3 entries with owner pointed the only User.

Then following code would throw the error:

var query = Parse.Query("House");
query.find().then(function(houses) {
    JSON.stringify(houses); // This would throw the following error with provided stack
})

TypeError: seen.indexOf is not a function. (In 'seen.indexOf(seenEntry)', 'seen.indexOf' is undefined)
encode — parse.js:11238
default — parse.js:11190
value — parse.js:4286
stringify

Work-around: I added a check to make sure seen is an array.

key: 'toJSON',
value: function (seen) {
var seenEntry = this.id ? this.className + ':' + this.id : this;
var seen = Array.isArray(seen)? seen: [seenEntry];
var json = {};
var attrs = this.attributes;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions