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.
Related
I'm using the-sett/elm-aws-core to get information from the AWS API, which unfortunately is very very inconsistent. Most of the endpoints return JSON and that works fine with that lib, which takes a JSON Decoder to make a request, but the EC2 endpoint returns XML (because why not).
The lib doesn't have any options not to decode JSON as far as I can tell, which does not work at all :
let ec2 region = Service.defineRegional "ec2" "2016-11-15" Service.QUERY Service.SignV4 (Service.setXmlNamespace "https://ec2.amazonaws.com/doc/2016-11-15/") region in
let params = [("Action", "DescribeImages"), ("Version", "2016-11-15"), ("Owner.1", "self")] in
Http.request "DescribeImages" GET "/" Http.emptyBody JSONDECODERHERE |> Http.addQuery params |> Http.send (ec2 region) creds |> Task.attempt msg
Failed : Problem with the given value:
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<DescribeImagesResponse .......
As you can see in there you need to pass a JSON Decoder to Http.request, but that, of course, fails when receiving XML. Is there a way to build a "fake" JSON decoder that would actually do nothing and just pass on the raw string? I tried using Decode. string but that's still actually decoding it, which fails. If there is a way I could then run an XML decoder manually on it in my update function, which would be fine.
Thank you
It's not possible to make a "fake" decoder that does what you want, because the problem isn't with the decoding. The problem is with the parsing, which is done before decoding. Parsing is the process of converting the string into a data structure typically called an Abstract Syntax Tree (AST), but since Elm compiles to JavaScript and JSON is also a subset of JavaScript the parse result of is really just a JavaScript object. Decoding is the process of turning that untyped data structure into a properly typed data structure.
It is therefore not possible to accomplish what you want with this API. Most likely you'll need to build the http request yourself and use elm/http directly.
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.
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.
I am building an application that I am dumping the data from one table into a json object. When I try to use this json object via angular I dont see the data. So I took the data from the json object and ran it in a parser and was told that there are too many characters in my json object. What is this limit?
Part 2, if this is the case, any ideas on how I could break up the data? Thanks
I was wondering if someone could tell me why I can't see the json response from a request that is also of type json in the JMeter View Results Tree. I know that the response is there because I use a regular expression to extract data (I wrote the reg ex based on result returned in Firebug). So the data can be extracted from the json response it just doesn't display in View Result Tree. I can see the json response for another request for a different app I performance test with JMeter, but that particular request is an ajax request. not sure
Add a sample writer and display content here.
http://jmeter.apache.org/usermanual/component_reference.html#Simple_Data_Writer
You will see the issue
HI there any one who looks in this post for jmeter, you may be bit worried when you cant find answers in internet regarding how to log your response when you sent a request , here is the solution and simple as it is...
just add a line like below.
result.setResponseData("put any content here to be displayed as String.", "UTF-8");
and check your response will be cool as you done.