我想一個JSON從laravel API轉換成陣列上離子3Ionic3:JSON到數組
這裏是我的JSON:
Object {id_oiseau: 1,
nom_commun: "Hirondelle",
lieu_signalement: "Foret",
date_signalement: "2017-05-16",
condition_signalement: "Aile coincee sous branche"…}
condition_signalement:"Aile coincee sous branche"
date_reception:"2017-05-16"
date_renvoi:"2017-05-02"
date_signalement:"2017-05-16"
descriptif_etat:"Aile cassee"
etat_actuel:"En attente de livraison"
id_acteur:1
id_adherent_lpo:1
id_local_lpo:1
id_oiseau:1
id_oiseau_dico:1
id_statut_oiseau:1
image:"bird-profil.jpg"
immatriculation:"EZ654ERRZ"
lieu_signalement:"Foret"
nom_codifie:"HIRON-NANT-4949845"
nom_commun:"Hirondelle"
pays:"France"
這裏提供商爲我的Ionic應用程序接收JSON:
export class BirdService {
returnedData;
headers: any;
options: any;
constructor(public http: Http) {
this.headers = new Headers();
this.headers.append('Content-Type', 'application/json');
}
getRemoteData(): Observable<any> {
return this.http.get('http://extranet.local/api/v1/bird/1', this.headers).map(res => res.json());
}
}
這裏是將JSON轉換爲函數:
export class HistoryPage {
constructor(public navCtrl: NavController, public serviceOne: BirdService) {}
ionViewDidLoad() {
this.serviceOne.getRemoteData().subscribe(
data => {
let list: History[] = data;
console.log(data);
});
}
}
它不起作用,因爲JSON文件留在JSON 「對象{..:.. ..:..}」
我試着用parseJSON與jQuery,但我不得不「無法讀取屬性未定義「parseJSON」」
import { jQuery } from 'jquery';
@Component({
selector: 'page-History',
templateUrl: 'History.html'
})
export class HistoryPage {
constructor(public navCtrl: NavController, public serviceOne: BirdService) {}
ionViewDidLoad() {
this.serviceOne.getRemoteData().subscribe(
data => {
var History = jQuery.parseJSON(data);
console.log(History);
});
}
}
而且我用角與fromJson但離子找不到名稱爲‘角’
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { jQuery } from 'jquery';
@Component({
selector: 'page-History',
templateUrl: 'History.html'
})
export class HistoryPage {
constructor(public navCtrl: NavController, public serviceOne: BirdService) {}
ionViewDidLoad() {
this.serviceOne.getRemoteData().subscribe(
data => {
var History = angular.fromJson(data);
console.log(History);
});
}
}
感謝您的幫助!
'console.log(data)'的輸出是什麼? –
我剛剛使用輸出 – TuxxyDOS
進行了編輯,您可以添加文本而不是圖片嗎? –