我只是想将文本从json文件输出到html,api在这里:https://shopify.statuspage.io/api
function setup() {
loadJSON("https://d33g96wd23dd.statuspage.io/api/v2/summary.json", gotData, 'jsonp');
}
function gotData(data) {
var output = document.getElementById('output');
output.innerHTML = data.status + ' ' + data.description;
}
<div class="w3-container w3-center" id="output"></div>
答案 0 :(得分:0)
如果要渲染数组的第一个元素,可以使用以下代码
import { HttpClient } from '@angular/common/http';
import { HttpClientModule } from '@angular/common/http'
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';
import { JsonStoresDataInterface } from './../../providers/stores/stores';
@Injectable()
export class StoresProvider {
private JsonStoresData = new Map();
defaultKey = "_1030003";
url_request = "path/to/json";
constructor(public http: HttpClient) {
}
getStoresRemote(){
this.http.get<JsonStoresDataInterface>(this.url_request).subscribe(data => {
var json = data.data;
for (var store of json.stores){
this.JsonStoresData.set(store.polygon_id, {
name: store.name,
description: store.description,
floor: store.floor[0],
image: store.pic_info.src,
uid: store.uid
})
}
});
console.log(this.JsonStoresData);//ok map
let keys = Array.from(this.JsonStoresData.keys());
let key = keys.find(key => key.includes(this.defaultKey));
console.log(this.JsonStoresData.get(key).floor);
//TypeError: Cannot read property 'floor' of undefined
}
}
否则,您可以交替循环您的append方法。