1) Give a description of the problem
I am using the API from the Naval Observatory to retrieve astronomical data about a specific location.
http://aa.usno.navy.mil/data/docs/api.php
When I get the data using a web request, the $response will not parse and returns an error.
2) What is the expected behavior?
When I submit the following query, I expect that I would retrieve astronomical data related to the location as JSON that I can parse to retrieve specific data about the location.
http://api.usno.navy.mil/rstt/oneday?date=9/18/2018&loc=Louisville,%20KY
{
“error”:false,
“apiversion”:“2.1.0”,
“year”:2018,
“month”:9,
“day”:18,
“dayofweek”:“Tuesday”,
“datechanged”:false,
“state”:“KY”,
“city”:“Louisville”,
“lon”:-85.75,
“lat”:38.22,
“county”:“Jefferson”,
“tz”:-5,
“isdst”:“yes”,
“sundata”:[
{“phen”:“BC”, “time”:“7:01 a.m. DT”},
{“phen”:“R”, “time”:“7:27 a.m. DT”},
{“phen”:“U”, “time”:“1:37 p.m. DT”},
{“phen”:“S”, “time”:“7:46 p.m. DT”},
{“phen”:“EC”, “time”:“8:13 p.m. DT”}],
“moondata”:[
{“phen”:“S”, “time”:“1:23 a.m. DT”},
{“phen”:“R”, “time”:“4:13 p.m. DT”},
{“phen”:“U”, “time”:“9:12 p.m. DT”}],
“nextmoondata”:[
{“phen”:“S”,“time”:“2:13 a.m. DT”}],
“closestphase”:{“phase”:“First Quarter”,“date”:“September 16, 2018”,“time”:“7:15 p.m. DT”},
“fracillum”:“66%”,
“curphase”:“Waxing Gibbous”
}
3) What is happening/not happening?
When I submit the query, I retrieve the response but the data appears to be altered. Although the return does appear to be a valid JSON when I look at it outside of WebCore. When I attempt to parse the data, an error is returned.
This is the value of $response stored in a variable and the elements appear to be out of order from the JSON data retrieved outside of WebCore. Because of the comma’s inside of data elements, parsing using ArrayItem is troublesome.
[apiversion:2.1.0,
city:Louisville,
closestphase:,
county:Jefferson,
curphase:Waxing Gibbous,
datechanged:false,
day:18,
dayofweek:Tuesday,
error:false,
fracillum:66%,
isdst:yes,
lat:38.22,
lon:-85.75,
month:9,
moondata:[[phen:S, time:1:23 a.m. DT],
[phen:R, time:4:13 p.m. DT],
[phen:U, time:9:12 p.m. DT]],
nextmoondata:[[phen:S, time:2:13 a.m. DT]],
state:KY,
sundata:[[phen:BC, time:7:01 a.m. DT],
[phen:R, time:7:27 a.m. DT],
[phen:U, time:1:37 p.m. DT],
[phen:S, time:7:46 p.m. DT],
[phen:EC, time:8:13 p.m. DT]],
tz:-5, year:2018]
**4) Post a Green Snapshot of the piston
5) Attach any logs (From ST IDE and by turning logging level to Full)
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: info â•” Event processed successfully (2954ms)
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: trace â•‘â•‘ Executed virtual command log (2ms)
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: trace â•‘â•” Execution stage complete. (2829ms)
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: trace â•‘â•‘ Executed virtual command parseJson (3ms)
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: trace â•‘â•‘ Executed virtual command log (3ms)
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: info â•‘â•‘ null
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: error â•‘â•‘ Error parsing JSON data [apiversion:2.1.0, city:Louisville, closestphase:, county:Jefferson, curphase:Waxing Gibbous, datechanged:false, day:19, dayofweek:Wednesday, error:false, fracillum:75%, isdst:yes, lat:38.22, lon:-85.75, month:9, moondata:[[phen:S, time:2:13 a.m. DT], [phen:R, time:4:57 p.m. DT], [phen:U, time:10:00 p.m. DT]], nextmoondata:[[phen:S, time:3:05 a.m. DT]], state:KY, sundata:[[phen:BC, time:7:02 a.m. DT], [phen:R, time:7:28 a.m. DT], [phen:U, time:1:37 p.m. DT], [phen:S, time:7:45 p.m. DT], [phen:EC, time:8:11 p.m. DT]], tz:-5, year:2018]
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: info â•‘â•‘ [apiversion:2.1.0, city:Louisville, closestphase:, county:Jefferson, curphase:Waxing Gibbous, datechanged:false, day:19, dayofweek:Wednesday, error:false, fracillum:75%, isdst:yes, lat:38.22, lon:-85.75, month:9, moondata:[[phen:S, time:2:13 a.m. DT], [phen:R, time:4:57 p.m. DT], [phen:U, time:10:00 p.m. DT]], nextmoondata:[[phen:S, time:3:05 a.m. DT]], state:KY, sundata:[[phen:BC, time:7:02 a.m. DT], [phen:R, time:7:28 a.m. DT], [phen:U, time:1:37 p.m. DT], [phen:S, time:7:45 p.m. DT], [phen:EC, time:8:11 p.m. DT]], tz:-5, year:2018]
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: trace â•‘â•‘ Executed virtual command setVariable (3ms)
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: info â•‘â•‘ Retrieved data from api.usno.navy.mil
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: trace â•‘â•‘ Executed virtual command log (4ms)
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: trace â•‘â•‘ Executed virtual command log (2ms)
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: debug â•‘â•‘ Calculating (string) Http content type: application/json + (string) >> (string) Http content type: application/json
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: debug â•‘â•‘ Calculating (string) Retrieved data from + (string) api.usno.navy.mil >> (string) Retrieved data from api.usno.navy.mil
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: info â•‘â•‘ Http content type: application/json
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: debug ║║ Cancelling statement #7’s schedules…
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: debug â•‘â•‘ Calculating (string) Http content type: + (string) application/json >> (string) Http content type: application/json
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: debug â•‘â•‘ Condition #10 evaluated true (7ms)
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: debug â•‘â•‘ Condition group #6 evaluated true (state did not change) (8ms)
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: trace â•‘â•‘ Executed virtual command log (2ms)
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: debug â•‘â•‘ Comparison (boolean) true is (boolean) true = true (2ms)
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: trace â•‘â•‘ Executed virtual command log (2ms)
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: info â•‘â•‘ true
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: trace â•‘â•‘ Executed virtual command httpRequest (651ms)
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:48 AM: info â•‘â•‘ 200
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:47 AM: debug â•‘â•‘ Calculating (string) http://api.usno.navy.mil/rstt/oneday?date=09/19/2018&loc= + (string) Louisville,%20KY >> (string) http://api.usno.navy.mil/rstt/oneday?date=09/19/2018&loc=Louisville,%20KY
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:47 AM: debug â•‘â•‘ Sending external web request to: api.usno.navy.mil/rstt/oneday?date=09/19/2018&loc=Louisville,%20KY
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:47 AM: debug â•‘â•‘ Calculating (string) http://api.usno.navy.mil/rstt/oneday?date= + (string) 09/19/2018 >> (string) http://api.usno.navy.mil/rstt/oneday?date=09/19/2018
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:47 AM: debug â•‘â•‘ Calculating (string) http://api.usno.navy.mil/rstt/oneday?date=09/19/2018 + (string) &loc= >> (string) http://api.usno.navy.mil/rstt/oneday?date=09/19/2018&loc=
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:47 AM: debug â•‘â•‘ Calculating (string) http:// + (string) api.usno.navy.mil >> (string) http://api.usno.navy.mil
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:47 AM: debug â•‘â•‘ Calculating (string) http://api.usno.navy.mil + (string) /rstt/oneday?date= >> (string) http://api.usno.navy.mil/rstt/oneday?date=
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:45 AM: info smartapp_pause called by smartAppName=webCoRE Piston, value=2000, smartAppVersionId=67c98787-3bac-483d-baf4-88a6c324e0d9
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:45 AM: trace â•‘â•‘ Waiting for 2000ms
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:45 AM: trace â•‘â•‘ Executed virtual command wait (1ms)
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:45 AM: debug ║║ Cancelling statement #1’s schedules…
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:45 AM: trace â•‘ Runtime (44139 bytes) successfully initialized in 70ms (v0.3.108.20180906) (120ms)
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:45 AM: trace â•‘â•š Execution stage started
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:45 AM: debug â•‘ RunTime Analysis CS > 23ms > PS > 70ms > PE > 26ms > CE
6bfed639-327d-4b9f-8bed-0f872117f12c 11:21:45 AM: info â•š Received event [Home].test = 1537370505232 with a delay of 0ms