javascript parse json
const json = '{ "fruit": "pineapple", "fingers": 10 }';
const obj = JSON.parse(json);
console.log(obj.fruit, obj.fingers);
javascript parse json
const json = '{ "fruit": "pineapple", "fingers": 10 }';
const obj = JSON.parse(json);
console.log(obj.fruit, obj.fingers);
perse json in angular
import { Component, OnInit } from "@angular/core";
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent implements OnInit {
name = "Angular";
stringJson: any;
stringObject: any;
courseList = [
{
courseid: "1",
coursename: "Java programming",
author: "Franc"
},
{
courseid: "2",
coursename: "Learn Typescript programming",
author: "John"
}
];
ngOnInit() {
// Convert String obect to JSON
this.stringJson = JSON.stringify(this.courseList);
console.log("String json object :", this.stringJson);
console.log("Type :", typeof this.stringJson);
// ConvertjSON to an object
this.stringObject = JSON.parse(this.stringJson);
console.log("JSON object -", this.stringObject);
}
}
angular convert response to json
getSomeDataFromSomeAPI(){
//res.json() does the trick, .json() function belongs to Response Object
return this.http.get("https://someApi.com/api/getData")
.map(res => res.json()).toPromise();
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us