Angularjs json stringify – angularjs parse json – angular to Json

JSON.parse using Angularjs

$http.get('api/index.php/get_live_appdata').success (function(data){
	if ($window.sessionStorage.getItem("live_data") === null) {
		$scope.live_data=data.data;			
	}
	else{
		$scope.live_data = JSON.parse($window.sessionStorage.getItem("live_data"));
	    $scope.sumtp = parseFloat($window.sessionStorage.getItem("sumtpdata"));				
	}
});

JSON.stringify using Angularjs

	$http.get('api/index.php/get_result_age_data/'+$routeParams.live_id).success (function(data){
		//$scope.result_age_data=data.data;
		if ($window.sessionStorage.getItem("result_age_data") === null) {
			$scope.result_age_data=data.data;
			var parameter = JSON.stringify({ander: data});
			$http.post('api/index.php/log',parameter).success (function(data){}); 
			
		}
		else{
			$scope.result_age_data = JSON.parse($window.sessionStorage.getItem("result_age_data"));
			 $scope.sumtill = parseFloat($window.sessionStorage.getItem("sumtill"));
			 $scope.sumageon = parseFloat($window.sessionStorage.getItem("sumageon"));
			 $scope.sumspark = parseFloat($window.sessionStorage.getItem("sumspark"));
			
		}
	});

angular.toJson using Angularjs

$window.sessionStorage.setItem("counter",$scope.counter);
$window.sessionStorage.setItem("rgsum",$scope.sum);
$window.sessionStorage.setItem("mysum",angular.toJson($scope.mysum));
$window.sessionStorage.setItem("subject_result_data",angular.toJson($scope.live_result));

router provider

Routing with get Query string

live24App.config(['$routeProvider',
  function($routeProvider) {
    $routeProvider.
      when('/', {
        title: 'Web Tutorials',
        templateUrl: 'mypage.html',
        controller: 'myCtrl'
      })
	   .when('/home/:live_id', {
        title: 'infinityknow.com',
        templateUrl: 'liveage.html',
        controller: 'liveCtrl'
      })
      .otherwise({
        redirectTo: '/'
      });
}]);

Example Of angular.toJson using Angularjs

Simple Serializes input Elements into a JSON-formatted convert string. and more Properties with leading like as a special char $$ sign to characters will be stripped since using AngularJS uses this simple notation internally.

READ :  C# Factorial program Tutorial with Examples

HTML part

 
 
In Controller
--------------
 $scope.showJson = function() {
    $scope.json = angular.toJson($scope.user);
}

Output
-------------
{{user | json}}

angular.isObject using angularjs

if a reference type is an Object type. Unlike typeof check in JavaScript, nulls value are not considered to be any objects. Note that JavaScript any arrays are init objects.

angular.isObject(value);
or
$scope.json = angular.isObject($scope.schools);

angular.isArray using angularjs

if a reference type is an any Array. simple Alias of new Array.isArray.

angular.isArray(value);
$scope.json = angular.isArray($scope.schools);

JSON.parse

angular.tojson

angular stringify