2017-09-05 12 views
-1

私はangle2を使用してノードapiからデータをフェッチしています。そのang2のjsonデータを分割する

{"height":{"low":4,"high":0,"unsigned":true},"currentBlockHash":{"buffer":{"type":"Buffer","data":[8,4,18,32,197,125,99,165,77,70,46,19,215,237,19,57,219,242,168,130,134,153,184,56,68,211,255,62,122,245,216,154,192,254,179,139,26,32,169,218,156,201,73,252,127,198,103,103,43,100,81,90,113,109,163,137,159,156,140,148,125,28,104,79,145,218,72,145,206,6]},"offset":4,"markedOffset":-1,"limit":36,"littleEndian":true,"noAssert":false},"previousBlockHash":{"buffer":{"type":"Buffer","data":[8,4,18,32,197,125,99,165,77,70,46,19,215,237,19,57,219,242,168,130,134,153,184,56,68,211,255,62,122,245,216,154,192,254,179,139,26,32,169,218,156,201,73,252,127,198,103,103,43,100,81,90,113,109,163,137,159,156,140,148,125,28,104,79,145,218,72,145,206,6]},"offset":38,"markedOffset":-1,"limit":70,"littleEndian":true,"noAssert":false}} 

のような形式でのノードのAPIが返すデータは、私だけangular2フロントエンドでlowの値を表示したいが、問題は、私は、キーと値のペアにそのJSONデータを分割することができませんです。 angular2は全データを表示するか、何も表示しません。 これは、JSON形式で

import {Component,OnInit} from '@angular/core'; 
import { AppService } from '~/./../app/app.service'; 

@Component({ 
    selector: 'dashboard', 
    styleUrls: ['./dashboard.scss'], 
    templateUrl: './dashboard.html' 
}) 
export class Dashboard implements OnInit { 

    constructor(private AppService: AppService) { 
    } 

    ngOnInit(){ 
     this.getStats(); 
    } 

    BlockchainHeight:any; 

    getStats(){ 
     this.AppService.getblockchaininfo().subscribe(data=>{ 
      console.log(data); 
      this.BlockchainHeight=data["_body"]; 
     }); 
    } 


} 

をデータを受信し、これは私のhtmlコードキーと値のペアにそのJSONデータを分割するための表示データが

<div class="row"> 
    <div class="col-xl-4 col-lg-4 col-md-4 col-sm-4 col-4"> 
    <ba-card> 
    <h3> Blockchain Height</h3> 
    {{BlockchainHeight}} 
    </ba-card> 
    </div> 

どれトリックまたは溶液である私のコンポーネントのコードですか?

+0

単なるバニラとオブジェクトにJSON文字列を変換します。 –

+0

'console.log(data)'は何を返しますか?この 'data [" _ body "]'とは何ですか? – 12seconds

答えて

0

イムないAngular2に関する詳細について確認が、これは、 `this.AppService.getblockchaininfo()`のコードを表示してくださいJavaScriptの

var jsonResponse = "{"height":{"low":4,"high":0,"unsigned":true},"currentBlockHash":{"buffer":{"type":"Buffer","data":[8,4,18,32,197,125,99,165,77,70,46,19,215,237,19,57,219,242,168,130,134,153,184,56,68,211,255,62,122,245,216,154,192,254,179,139,26,32,169,218,156,201,73,252,127,198,103,103,43,100,81,90,113,109,163,137,159,156,140,148,125,28,104,79,145,218,72,145,206,6]},"offset":4,"markedOffset":-1,"limit":36,"littleEndian":true,"noAssert":false},"previousBlockHash":{"buffer":{"type":"Buffer","data":[8,4,18,32,197,125,99,165,77,70,46,19,215,237,19,57,219,242,168,130,134,153,184,56,68,211,255,62,122,245,216,154,192,254,179,139,26,32,169,218,156,201,73,252,127,198,103,103,43,100,81,90,113,109,163,137,159,156,140,148,125,28,104,79,145,218,72,145,206,6]},"offset":38,"markedOffset":-1,"limit":70,"littleEndian":true,"noAssert":false}} "; 
var decodedJsonObject = JSON.parse(jsonResponse); 
var low = decodedJsonObject.height.low; 
関連する問題