{ "on" => true } gets transformed to { "on" => True } (uppercase "T") as part of the payload, resulting in invalid JSON.Looks like this was fixed in Garmin Connect Mobile, but it's still broken in the simulator.
I cannot reproduce this with a local test case on the simulator using the 2.3.4 SDK.
The following is my simple python HTTP server..import BaseHTTPServer
import json
class MockRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def init(self):
pass
def do_GET(self):
message_body = {
"array" : [ "A" ],
"dict" : { 1 : "2" },
"float" : 1.23,
"double": 3.1415926535897932,
"number": 123,
"long" : 2147483648,
"string": "hello",
"boolean": True
}
content_type = "application/json"
message_body = json.dumps(message_body)
self.send_response(200)
self.send_header("Content-Type", content_type)
self.send_header("Content-Length", len(message_body))
self.end_headers()
self.wfile.write(message_body)
print 200
print "Content-Type: {}".format(content_type)
print "Content-Length: {}".format(len(message_body))
print ""
print message_body
def _main():
server_address = ('', 8080)
httpd = BaseHTTPServer.HTTPServer(server_address, MockRequestHandler)
httpd.serve_forever()
if __name__=='__main__':
_main()
Here is my MonkeyC application code.
using Toybox.Application as App;
using Toybox.Lang as Lang;
using Toybox.System as Sys;
using Toybox.WatchUi as Ui;
using Toybox.Graphics as Gfx;
using Toybox.Communications as Comm;
class TestBehaviorDelegate extends Ui.BehaviorDelegate
{
hidden var _view;
hidden var _pending;
function initialize(view) {
BehaviorDelegate.initialize();
_view = view;
_pending = false;
}
function onSelect() {
if (!_pending) {
_pending = true;
var url = "http://localhost:8080";
var params = {
};
var options = {
//:headers => {
// "Content-Type"=> Comm.REQUEST_CONTENT_TYPE_JSON
//},
//:method => Communications.HTTP_REQUEST_METHOD_GET,
//:responseType => Comm.HTTP_RESPONSE_CONTENT_TYPE_FIT
//:responseType => Comm.HTTP_RESPONSE_CONTENT_TYPE_JSON
};
Comm.makeWebRequest(url, params, options, method(:onWebResponse));
_view.onWebRequest(url);
}
return true;
}
function onWebResponse(code, data) {
_view.onWebResponse(code, data);
_pending = false;
}
}
class TestView extends Ui.View
{
hidden var _code;
hidden var _data;
hidden var _pending;
function initialize() {
View.initialize();
_pending = false;
}
function onUpdate(dc) {
dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_BLACK);
dc.clear();
var cy = dc.getHeight() / 2;
var cx = dc.getWidth() / 2;
var color = Gfx.COLOR_GREEN;
if (_pending) {
color = Gfx.COLOR_RED;
}
dc.setColor(color, color);
dc.fillCircle(cx, 10, 7);
dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_BLACK);
if (_code != null) {
var fy = dc.getFontHeight(Gfx.FONT_LARGE);
dc.drawText(cx, cy - fy, Gfx.FONT_LARGE, _code.toString(), Gfx.TEXT_JUSTIFY_CENTER);
if (_data != null) {
dc.drawText(cx, cy, Gfx.FONT_XTINY, _data.toString(), Gfx.TEXT_JUSTIFY_CENTER);
}
}
}
function onWebRequest(url) {
_pending = true;
Ui.requestUpdate();
}
function onWebResponse(code, data) {
Sys.println(code);
Sys.println(data);
if (data != null) {
data = data.toString();
}
_code = code;
_data = data;
_pending = false;
Ui.requestUpdate();
}
}
class TestApp extends App.AppBase
{
function initialize() {
AppBase.initialize();
}
function getInitialView() {
var view = new TestView();
return [ view, new TestBehaviorDelegate(view) ];
}
}
C:\Test>python test.py
127.0.0.1 - - [06/Nov/2017 06:45:14] "GET / HTTP/1.1" 200 -
200
Content-Type: application/json
Content-Length: 151
{"boolean": true, "dict": {"1": "2"}, "string": "hello", "double": 3.141592653589793, "array": ["A"], "float": 1.23, "number": 123, "long": 2147483648}
200
{number=>123, dict=>{1=>2}, string=>hello, boolean=>true, array=>[A], long=>2147483648, float=>1.230000, double=>3.141593}