Google Groups

Re: [angular.js] Problem with the way $resource deserializes a json representation of an array of strings.


Carlos Serrano Apr 12, 2012 1:43 AM
Posted in group: AngularJS
It makes sense. Thanks for the explanation Misko.

Thanks for the idea about using interceptors zdam .
In the end I´m using $http in its simplest form beause its enough for me but the interceptors are an interesting  functionality.

Carles

On Wednesday, April 11, 2012 5:28:58 PM UTC+2, Misko Hevery wrote:
Resource is an OO wrapper over your data. For example Book would be a resource. So that you can do

var book = new Book();
book.save()

Since book is an object, having primitive types makes no sense.

On Wed, Apr 11, 2012 at 2:44 AM, zdam <adam.k...@gmail.com> wrote:
You could write a responseInterceptor to convert your array to objects and then be able to use resource: (resource uses http so the response Interceptor would be invoked when using a resource) http://docs-next.angularjs.org/api/angular.module.ng.$http 


On Wednesday, 11 April 2012 17:23:58 UTC+10, Carles Serrano wrote:
Thanks for the clarification Misko.

I´ve changed to $http and everything works fine now.
Could you please explain why $resource only work with objects? 

Thanks again for the clarification and for the rapid response. This problem was driving me nuts.

Carles.



On Tuesday, April 10, 2012 8:00:12 PM UTC+2, Misko Hevery wrote:
If you need to consume array of strings, then you need to use $http

On Tue, Apr 10, 2012 at 10:59 AM, Misko Hevery <mi...@hevery.com> wrote:
Resources works on objects. So server needs to return an array of objects, not array of strings.


On Tue, Apr 10, 2012 at 8:44 AM, Carles Serrano <carp...@gmail.com> wrote:
Hi guys

 I´m having problems deserializing an array of strings in json using $resource.

The json the server is sending is: 

["Name1","Name2","Name3"]

but $resources deserializes the json retrieved from the server like:


[["N","a","m","e","2"], ["N","a","m","e","2"], ["N","a","m","e","2"]]

This is how I call the $resource object.

$resource('/route/to/resource').query();

Here is a non working example in fiddle: 

http://jsfiddle.net/carpasse/96EU5/

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/_It7MqaBHREJ.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/RmELmEn1EeQJ.

To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.