0

I want to convert a string to and Object and below is my code

$scope.myString = "{'profit': 2.276273727416992}";
$scope.result = angular.toJson($scope.myString);
console.log('is object = ' + angular.isObject($scope.result)); // false

I'm using angular.toJson() for conversion to but its not working out. Please let me know what is wrong here and how can I convert

1 Answer 1

1

You need to use angular.fromJson to deserialize a JSON string. (link)

Moreover, json requires double quotes:

$scope.myString = "{\"profit\": 2.276273727416992}";
$scope.result = angular.fromJson($scope.myString);
console.log('is object = ' + angular.isObject($scope.result)); // true
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.