2016-10-20 21 views
0

我已經使用JSON.parse(data.Body)它給我正確的結果,這是一個對象。angular.fromJson(data.Body)vs JSON.parse(data.Body)

,因爲我NPM運行皮棉,它給我的錯誤:「你應該使用angular.fromJson methof代替JSON.parse

這是我的代碼:this.$log.log(angular.fromJson(data.Body), JSON.parse(data.Body));

enter image description here

我不明白什麼是第一個輸出,Uint8Array?

我該怎麼做才能得到相同的結果?我不需要無符號整數.... 的data.Body是一個整數數組只,但是當我做了JSON.parse,它是一個對象 enter image description here

哪裏是我的對象???? ?!

+0

'UInt8Arrays'是無符號8位整數的數組 - 參見[Javascript typed arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays )。 –

+0

告訴我們什麼是'data.Body'。 angular.fromJSON只是JSON.parse()的一個包裝,用於檢查參數是否爲字符串 –

+0

@Maximus我已更新 –

回答

2

在這裏有一個很好的例子:

VAR strJSON = ' { 「名」: 「mital」, 「時代」:25, 「地址」: 「印度」 }'; document.write(angular.fromJson(strJSON)); document.write(「」);
1

還有一個解決方案,請添加angular.toJson而不是angular.fromJson。 這裏是我的例子:var jsonData={ "links":[ {country: "india", state: "gujarat"} ] document.write(angular.toJson(jsonData))