Reputation: 233
When I use JSON.stringify on a Parse.com query object, it only includes the "attributes" and ignores the rest. How do I stringify the entire object?
// load races from Parse var Events = Parse.Object.extend("Events"); var query = new Parse.Query(Events); query.equalTo("theYear", currentYear); query.ascending("sortOrder"); query.find({ success: function(results) { forgeLog("Got "+results.length+" Events from Parse"); forgeLog("First object in array logged directly:"); forgeLog(results[0]); forgeLog("First object in array with stringify:"); forgeLog(JSON.stringify(results[0])); }, error: function(error) { forgeLog("Error getting Events from Parse"); } });
{ attributes: { Name: 'McCalls Motorworks', raceId: '0', sortOrder: 2, theYear: 2012 }, _operations: {}, _dirty: {}, _hashedJSON: {}, _escapedAttributes: {}, cid: 'c0', id: 'To6lLjzwQw', createdAt: '2012-08-09T13:51:29.259Z', updatedAt: '2012-08-10T13:23:07.280Z', _setting: false, _previousAttributes: { Name: 'McCalls Motorworks', raceId: '0', sortOrder: 2, theYear: 2012 } }
{"Name":"McCalls Motorworks","raceId":"0","sortOrder":2,"theYear":2012}
Update: I actually just tested myself and it works when I manually define the object by cut and pasting the first object and defining the variable myself. However, when I stringify the result directly after receiving it from Parse (as in example code), it only returns the attributes portion...yet the first object is what I copied directly from my console when logging the result from Parse before attempting to stringify.
Upvotes: 1
Views: 1688
Reputation: 233
Héctor from Parse was able to explain it to me:
This is because createdAt, objectId, updatedAt, are not attributes. They are properties of the object itself, so they are not being picked up by the JSON serializer.
Upvotes: 0
Reputation: 1380
yap i have also checked on many of browser but getting everything working fine its not giving any problem manually
what i think you are directly setting parser value in JSON.stringify
some times it happens with js
try one thing intialize it in some object and pass that object in JSON.stringify
may it work
Upvotes: 0