I am currently developing a hobby application that uses Angular for the front-end and Python for the back-end. In this setup, a component in Angular sends an HTTP GET request to Python, which responds with a jsonpickled object.
My goal is to decode the jsonpickled object received in the HTTP response. The decoding process will take place in the component.ts file of Angular where the HTTP RESPONSE object is received.
Even though I followed the instructions provided in example files, specifically this repository (I referenced the testUnpickle.html file under the tests directory), the code within the script tags did not execute as expected.
Here is the snippet of code from 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 contains the jsonpickled object that needs to be unpickled to get a File Object.
console.log(response)
}
)
}
Below is a snippet from the 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>