javascript - How to convert string of objects to JSON object in angular transformRequest -


so i'm receiving string:

{"id":"0-worfebvjyyvqjjor","size":17,"price":921,"face":"( .-.)","date":"mon jan 04 2016 22:55:30 gmt+0000 (gmt standard time)"} {"id":"1-ifma3yxxccgzaor","size":19,"price":98,"face":"( .o.)","date":"fri jan 08 2016 16:11:25 gmt+0000 (gmt standard time)"} {"id":"2-sa3iurvt4hv0lik9","size":14,"price":659,"face":"( `·´ )","date":"sun jan 03 2016 06:20:28 gmt+0000 (gmt standard time)"} {"id":"3-bc3tf55q9vx11yvi","size":33,"price":361,"face":"( ° ͜ ʖ °)","date":"fri jan 01 2016 22:49:22 gmt+0000 (gmt standard time)"} 

here in console.log(data):

var warehouseresource = $resource('/api/products?limit=10', {}, {     query: {         method: 'get',         isarray: false,         transformresponse: function(data) {             console.log(data);         }     } }); 

how convert data json array?? tried json.parse(data) throws error.

if want data array, might wanna set isarray true

var warehouseresource = $resource('/api/products?limit=10', {}, {     query: {         method: 'get',         isarray: true     } }); 

this assuming string representation receive in valid format. can see , missing after each object. expected? if yes, might want replace } },, wrap them in '[]' , angular.fromjson(data) in transformer.

here's plunker that: https://plnkr.co/edit/zglk7ptclapvnwuilm1t?p=preview


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -