0

I am developing a function which return me json string from rest service to js. For this I develop a function on a button click which return me json string and call rest service. My js call click function is like -

 $scope.try = function () {
 alert("Hi")

  Restangular.one("tasks/try").get().then(function (data) {
  alert(data);
  });
 };

And my rest code for this call is -

@GET
@Path("/try")
@Timed
@Produces("application/json")
public String create() {

    return "{\"id\":1,\"name\":\"A green door\",\"price\":12.5}";
}

I want this json string in ui as it is but it return me this string as object. I use angular js v1.3.16, jersey client v2.22.2 and spring. Please provide me some solution. Thanks in advance.

8
  • dont use alert inside the function it will show object instead alert use console.log(data) to print the data Commented Jun 6, 2016 at 6:54
  • I have tried this. The data is in Object from even I return it as json string Commented Jun 6, 2016 at 6:56
  • can u show as the response in console log Commented Jun 6, 2016 at 6:58
  • My console log is 'Object {id: 1, name: "A green door", price: 12.5, route: "tasks/try", reqParams: Object…}' Commented Jun 6, 2016 at 7:02
  • This give me error in console " SyntaxError: Unexpected token o in JSON at position 1" Commented Jun 6, 2016 at 7:16

1 Answer 1

1

Your response is restangularized. Please see How to unrestangularize

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.