angular.fromJson和JSON.parse之间有什么主要区别吗?所以我们需要使用angular.fromJson.
不同之处在于angular.fromJson
仅在类型为a时才解析并返回输入数据string
.否则返回输入.
https://github.com/angular/angular.js/blob/master/src/Angular.js#L1323-L1339
/** * @ngdoc function * @name angular.fromJson * @module ng * @kind function * * @description * Deserializes a JSON string. * * @param {string} json JSON string to deserialize. * @returns {Object|Array|string|number} Deserialized JSON string. */ function fromJson(json) { return isString(json) ? JSON.parse(json) : json; }