api - Bittrex API 返回“结果”[object Object]
问题描述
使用 Angular 6 我无法弄清楚如何从 Bittrex API 请求https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-ltc显示“结果”数组
我可以获取 API,没问题并显示对象,但结果数组像 [object Object]
成功 true
消息
结果 [object Object]
这是HTML代码:
<tr *ngFor="let price of objectKeys(prices)">
<td>{{ price }}</td>
<td>{{ prices[price] }}</td>
</tr>
我只想知道正确的 HTML 代码来显示结果数组中的任何一个参数。任何帮助,将不胜感激。
谢谢
编辑:添加完整代码
数据服务:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { HttpHeaders } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class DataService {
result: any;
constructor(private http: HttpClient) { }
getPrice() {
return this.http.get('https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-ltc')
}
}
组件.ts:
import { Component } from '@angular/core';
import { DataService } from './data.service';
import { Observable } from 'rxjs';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
objectKeys = Object.keys;
prices: any;
constructor(private data: DataService) {
}
ngOnInit() {
this.data.getPrice()
.subscribe(res => {
this.prices = res;
});
}
}
组件.html
<h2>Bittrex Results</h2>
<div *ngIf="prices">
<table id="pricetable">
<tr>
<th>Bittrex Close</th>
<th>Bittrex Volume</th>
<th>Test</th>
</tr>
<tr *ngFor="let price of objectKeys(prices)">
<td>{{ price }}</td>
<td>{{ prices[price] }}</td>
<td>{{ prices[price] }}</td>
</tr>
</table>
</div>
解决方案
正如您在获得的 JSON 中看到的那样,该对象包含一个名为的属性,该属性result
是包含价格的数组。
所以你必须使用这个属性,像这样:
this.data.getPrice()
.subscribe(res => {
this.prices = res.result;
});
推荐阅读
- spring - 在 IBM MQ 中按计划交付消息 - 提前多长时间?
- php - 正则表达式匹配 next 是空格或字符串结尾
- localhost - 自签名根证书仍然无效
- android-studio - 如何将数据从 Raspberry Pi Python 脚本发送到 Android 应用程序
- faster-rcnn - 是否可以在更快的 R-CNN 中使用我自己的 CNN 模型?
- python - 寻找K-mean距离
- python - 如何将 ASCII 转换为位串(二进制)
- php - PHP:没有可读的输出,当我使用小于符号时,结合 var_dump() 函数
- swift - 移除 UISearchController 后,NavigationItem 不会恢复到原来的大小
- firebase - Firebase 存储 - 图像预览正在永久加载