如何可以解析JSON數據離子2的Json解析
數據= 「{\」 MSG_OK \ 「:\」 初級會員olusturuldu \ 「\ 」USER_ID \「:181,\ 」令牌\「:\」 8650bfe987a3d619445f3d4905e1ae863e4be85f \ 「}」
我想用令牌數據
我想這樣的代碼,但沒有工作..
感謝名單到現在
var headers = new Headers();
headers.append('Accept', 'application/json');
headers.append('Content-Type', 'application/json');
//headers.append('Authorization' , 'Basic '+ btoa(tok));
let options = new RequestOptions({ headers: headers });
let postParams = {
username: this.uyelik['username'],
email:this.uyelik['email'],
password:this.uyelik['password']
}
this.http.post("https://deneme.com/api/v1.0/users/", postParams, options)
.subscribe(data => {
console.log(data['_body']);
this.veri = data['_body'];
this.veri = JSON.parse(this.veri);
console.log(this.veri['token']);
}, error => {
console.log(error);// Error getting the data
});
我解決了問題;
var headers = new Headers();
headers.append('Accept', 'application/json');
headers.append('Content-Type', 'application/json');
//headers.append('Authorization' , 'Basic '+ btoa(tok));
let options = new RequestOptions({ headers: headers });
let postParams = {
username: this.uyelik['username'],
email:this.uyelik['email'],
password:this.uyelik['password']
}
this.http.post("https://iothook.com/api/v1.0/users/", postParams, options)
.subscribe(data => {
//console.log(data['_body']);
veri = data['_body'];
veri= veri.slice(1, -1);
veri = veri.replace(/\\/g, "");
veri = JSON.parse(veri);
console.log(veri.token);
}, error => {
console.log(error);// Error getting the data
});
做映射。像這樣的東西 返回this.http.post(this.baseUrl + endUrl,param,options) .map((res:Response)=> res.json()); –
嗯,我的代碼是在旁邊工作? –