Angular 6 HttpClient not converting response to Interface - angular6

I have an api endpoint that responds with a JSON Array as a string.
Correspondingly, I have an interface that matches the JSON response
I have a service that makes the request to get the array of users and logs the first record to the console.
Expected Results
I expect to get a UserDetails object back and should print all the contents of index 0 to the console.
Actual Results
In the console I just see the character '['. It seems that res variable is still being treated as a string, and not a UserDetails array.
I have been struggling for house to try and figure out what is causing this behavior

I found the problem for anyone who is interested.
My server is returning the response in the body as a JSON string (this is a requirement from AWS API Gateway). The following has to be done to get the data to correctly parse.

Related

Beego get response body in middleware after processing

I have to append parameter in JSON response after request processing is completed and before sending. I can do in after exec filter. Here I defined filter like this,
beego.InsertFilter("*", beego.AfterExec, AddRequestAfterExec, false)
Now in this AddRequestAfterExec method, I am unable to read JSON response. I need to read JSON response and add parameter to it. I searched many things, but did not find any thing useful. So far I have left it empty.
func AddRequestAfterExec(c *context.Context) {}
Can anybody help, how to read Response in this function and modify it?
Also I am sending response from API controller like this
authController.ServeJSON()

angular 4 http get request doesnt subscribe to json response (mongoose result) from api

the http client get request to the api, works I see that a json object is being returned with the command
res.send (data) after finding it in Mongoose.
I understand that httpclient now sends standard json format back from the api, however I don’t understand how to subbscribe to this data on the client side. How do I receive the object that is being send back with res.send.
I added an interface to the get request that sets up the variables that tie in with the json object.
However I can’t get the data nor do I get any failures as if the .subscribe is not being called.
I am using the httpclient docs but somehow I can’t get it to work.
Below the get request that I am using “might not be entirely correct” which works but the obj doesn’t get subscribed to
http.get(url, {params})
.subscribe (data => {console.log(data)});
}
ie. I get no error, which I expect as the log can’t read json format?

Parsing JSON with Node Red with telegram bot

I am trying to get JSON working with my telegram bot which I have already created. I can the bot send and receive message in the debug screen from telegram in Node Red.
I want to take the return api message from telegram and then parse it out to eventually have it do something like turn on the led if I send it "LED-ON" command or similar.
Currently I see this type of JSON format. And I want to basically parse the content field out from the JSON object to get me LED-ON.
{
"chatId":64XXXXX7,
"messageId":337,
"type":"message",
"content":"LED-ON",
"date":"2017-09-09T07:07:38.000Z",
"inbound":true
}
I used the JSON node but from the debug it only changes the message from json object to json string. But I still can't parse out LED-ON.
Also if once i get LED-ON filtered and send it out to a split node to generate a MQTT message to turn the LED, do I need it to be a object or string? Sorry I just am very new to programming.
I can share flow if it dosen't make sense.
There is no need for the JSON node if the content is already a JSON object.
I'm at a loss as to why you would need a split node, a switch node or a function node should be all that is needed to test the value in msg.payload.content
The MQTT node will always convert any outbound msg.payload to a string before publishing.
EDIT:
All nodes (including function nodes) need to return an object. The msg.payload should normally hold the "output" from a node, Also no need to declare msg as it is already in scope, so in the case of your example it should be:
msg.payload = msg.payload.content;
return msg;
Also you may do better asking questions like this on the Node-RED Slack team (linked from the Node-RED home page) as it's likely to need a little back and forth, which Stack Overflow is not best suited to.

Parse.com cloud httpRequest response.text does not convert to JavaScript object

I have a http request I am trying to make on an afterSave method in my Cloud Code. I have been able to create my request, and when I console.log(response) it outputs a block that contains the information that I am after. I am aware that response.text is a string so I am trying to run JSON.parse(response.text) so I can access my API response.
I can print out what appears to be an object after running JSON.parse, but much of the data within my response is stripped out. I know it is not the fault of the API because I have another function that runs on the client with the same query and it works correctly.
What is the correct way to parse the response.text from a Parse.Cloud.httpRequest to maintain my data.
Try var result = JSON.parse(response['text']).

Cocoa touch - Error getting JSON key

So I am parsing the www.twitch.tv API json page.
Here is the link: (these 2 people are normally always streaming - if the json data shows as [] it means they are offline. if someone is offline, json has no data)
http://api.justin.tv/api/stream/list.json?channel=vokemodels
http://api.justin.tv/api/stream/list.json?channel=mathmind
My problem is that in my iOS application, I can do:
[dictionary objectForKey:#"stream_count"]];
And I do successfully get data from the JSON and it will log correctly. However, when trying to get data from the "screen_cap_url_medium" key, I do the following code:
[dictionary objectForKey:#"screen_cap_url_medium"]];
And I get a (null) when logging. I am absolutely positive I am retrieving the JSON data, and I do not have any typos.
When I NSLog the entire JSON array from one of the above links, the "screen_cap_url_medium" is one of the only keys that are in quotes.
Can anyone tell me what I'm doing wrong?
If you inspect your json you'll see that screen_cap_url_medium is under channel object, so you can access it like this:
[dictionary valueForKeyPath:#"channel.screen_cap_url_medium"];
PS. Here dictionary is obviously the first object of the root array you get back from your response.