I'm trying to parse the result of a database query in a server script. The query works and the result comes back ok.
code
result.query = Collection.query(DB_id, "Product", params, token);
console.log(result);
/code
The result variable that is returned from the query brings back the object containing an array. It looks like this on the trace:
{ query: [ { _createdAt: [Object], _id: '5221c2a4e4b0899403d2afb5', _updatedAt: [Object], acl: [Object], available: true, category1: 'Pasta', description: 'The classic dish', entity_code: 'stef1', name: 'Spaghetti', price: 23, productlist_code: 'A', sort_order: 3 }, { _createdAt: [Object], _id: '535269b5e4b0e44dd0271627', _updatedAt: [Object], acl: [Object], available: true, category1: 'Pasta', description: 'Lovely blah', entity_code: 'stef1', name: 'Blah', price: 20, productlist_code: 'A', sort_order: 5 } ] }
That looks good to me. However, if I try to iterate the result to get the object ids using a loop like this:
code
for (var i = 0; i < result.length; i++) { etc...
/code
then it says that result.length is undefined. I guess this might be because result is a string and not an object?
If I try to turn result into an object using:
code
var obj = jQuery.parseJSON( result );
/code
I get the following error message: jQuery is not definedncode: undefined
My questions: (1) why is jQuery not recognised?
(2) how do you recommend parsing the json that is returned from the query?