我想一个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
进行了编辑,您可以添加文本而不是图片吗? –