I'm creating an hobby application where Angular is front-end and Python is acting as back-end. A component in Angular is sending HTTP GET to Python upon which python responds with a jsonpickled object.
I wish to unpickle (decode) the jsonpickled object received in HTTP RESPONSE. The unpickle (decode) would happen in Angular's component.ts file where the HTTP REPSONSE object is received.
Followed the instructions as per example files here, but it is not working: https://github.com/cuthbertLab/jsonpickleJS (under tests directory there's testUnpickle.html file which I had used as reference but the part within script tags just doesn't execute).
Below is the code in Angular's component.ts file:
ngOnInit() {
this.id = this.route.snapshot.params['id'];
this.url = 'http://127.0.0.1:5000/api/restaurants/' + this.id
this.http.get(this.url).subscribe(
response =>
{
this.name = response['name'];
this.location = response['location'];
this.photos = response['photos']; // this is the jsonpickled object, I want to unpickle it so as to get a File Object.
console.log(response)
}
)
}
Below is snip from component.html file:
<body>
<script type="text/javascript" src="../../assets/jsonpickleJS-master/build/jsonpickle.min.js"
data-main= "jsonpickleJS/main"></script>
<script type="text/javascript">
picfileobj = jsonpickle.decode(photos)
console.log("getting decoded file for pic")
console.log(picfileobj)
</script>
</body>
Able to decode the jsonpickle object received in HTTP RESPONSE using below.