convert JSON format string into Object using AngularJS – angular json
I am working on a example simple defect where I am getting here string data as a JSON Object but in view its auto simple converting to string and json object. As a so result I am new unable to sort it.
For example:
Use Simple JSON.parse(jsonStr); to angular.tojson used
This would return we a JSON simple object that we can use
You simple could just use AngularJS: “var jsObj = angular.fromJSON(
in javascript – simple use stringify function or method to convert data the json to any string, and all the parse(jsonstring) to simple convert the string to json data.In this post will you show convert JSON format string into Object using AngularJS – angular json
[php]
var str = ‘{“key”: “value”, “key2”: “value2”}’;
var realjsonObj = JSON.parse(str);
[/php]
Filter and Convert JSON object to String Example
[php]
[/php]
Convert JSON to HashMap and HashMap to JSON
[php]
———————
$http.get(“live24u/You/Get/Data.php”).success(function(response){
for (var i = 0, len = response.length; i < len; i++){ response[i].fullname = JSON.parse(response[i].fullname); $scope.productss = response } }) [/php]
angular.fromJson Example
Simple Deserializes a JSON string.(angular.fromJson(json);)
[php]
var json = ‘{“name”:”rajkot”,”likes”:{“fruit”:[“ganesg”,”tirupati”,”satyam”]}}’;
var obj = angular.fromJson(json);
console.log(obj.likes.fruit[1]);
[/php]
How to convert JavaScript object into JSON string using AngularJS json filter
AngularJS
[php]
(function () {
‘use strict’;
angular
.module(‘liveApp’, [])
.controller(‘liveCtrl’, liveCtrl);
liveCtrl.$inject = [‘$filter’]
function liveCtrl ($filter){
var vm = this;
vm.products = {
ISBN: “458-1-989-2015-3”,
Title: “live24u AngularJS”,
Price: 45.00,
Pages: 408,
Authors: [ “dsp patel”, “happys dipus” ]
};
}
console.log($filter(“json”)(vm.products));
})();
[/php]
HTML
[php]
{{ vm.products | json }}
[/php]
JSON.stringify() Example
The JSON.stringify() function or method converts a simple JavaScript latest json value to a JSON string, convert to optionally replacing all the data or content values if a replacer all of the function is specified value, or optionally new simple including only all the specified range and loop to properties and param if a replacer json object to array is specified.
JSON.stringify(value[, replacer[, space]])
[php]
JSON.stringify({}); // ‘{}’
JSON.stringify(true); // ‘true’
JSON.stringify(‘foo’); // ‘”foo”‘
JSON.stringify([1, ‘false’, false]); // ‘[1,”false”,false]’
JSON.stringify({ x: 5 }); // ‘{“x”:5}’
[/php]