On Mon, 21 Nov 2016 05:56:47 GMT, John More wrote:
I have been trying to work this problem all day and can not resolve it.
I get some Json data from a restful service and after a res.readJson() store the data in a file. I then deserialize the data into a D struct. So far so good.
I placed the data in a file so I can use it for other processing. When I read the data from the file it will no longer deserialize into the D struct.
I have tried many variations throughout the day to no avail. The code snippets below are my last attempt.
Any assistance is deeply appreciated.
Thanks John
Json getDevices(string groupId) {
Json anEmptyDevice;
//anEmptyDevice.length = 1;
string completeURL = "xxxxxxxxxxxxxxxxxxxxxxx";
HTTPClientResponse res = requestHTTP(completeURL,(scope req) { req.method = HTTPMethod.GET; req.addBasicAuth("xxxx","xxxxx"); req.headers["Accept"] = "application/json"; }
);
if (res.statusCode != 200) {
logInfo("Check Internet connection, and try again!"); logInfo("Server response is: " ~ to!string(res.statusCode)); return anEmptyDevice;
}
else {logInfo("return code was ok ",res.statusCode); auto theData = res.readJson(); File file = File("/home/john/Documents/pfGroups/deviceData", "w"); file.rawWrite(to!string(theData)); file.close(); return theData;
}
}The following code calls the above code.
void main() {
auto theDevices = getDevices("c0cd774d-e27a-4d86-bad6-77e3400ea5c9");
auto myData = to!string(read("/home/john/Documents/pfGroups/deviceData"));
devices = deserializeJson!(Device[])(theDevices);// This fails with this error std.json.JSONException@../../../.dub/packages/vibe-d-0.7.29/source/vibe/data/json.d(1789): Expecting ',' or '}', not '"'.
Device[] devices = deserializeJson!(Device[])(myData);
}THE DATA AS RETURNED FROM THE HTTP REQUEST amd WRITTEN TO THE FILE and it will deserialize
[{"licenseStatus":"Full","managementStatus":"Managed","name":"Canon iR5070 36.04","type":"Network","firstReportedAt":"2016-02-29T15:21:43.61Z","macAddress":"00-00-85-48-68-08","lastReportedAt":"2016-11-21T05:09:41Z","groupId":"2012e2d7-5723-484b-b821-4019c128aed8","status":"Ok","id":"53cf228d-c997-42d1-ab65-59876b4b4cc6","ipAddress":"192.168.2.20","modelMatch":{"modifiedAt":"2016-11-21T04:11:31.83Z","model":{"name":"Canon imageRUNNER 5070","manufacturer":"Canon","id":"be767c7a-9125-43c4-bd2e-95087fbc893d","hasImage":true,"isColor":false},"type":"AutoOne","isAutoMatchEnabled":true}}]THE DATA AS READ FROM THE FILE and it will NOT deserailize
[{"licenseStatus":"Full","managementStatus":"Managed","name":"Canon iR5070 36.04","type":"Network","firstReportedAt":"2016-02-29T15:21:43.61Z","macAddress":"00-00-85-48-68-08","lastReportedAt":"2016-11-21T05:09:41Z","groupId":"2012e2d7-5723-484b-b821-4019c128aed8","status":"Ok","id":"53cf228d-c997-42d1-ab65-59876b4b4cc6","ipAddress":"192.168.2.20","modelMatch":{"modifiedAt":"2016-11-21T04:11:31.83Z","model":{"name":"Canon imageRUNNER 5070","manufacturer":"Canon","id":"be767c7a-9125-43c4-bd2e-95087fbc893d","hasImage":true,"isColor":false},"type":"AutoOne","isAutoMatchEnabled":true}}]THE DATA AS RETRUNED FROM THE CALL TO getDevices and it will deserialize
[{"licenseStatus":"Full","managementStatus":"Managed","name":"Canon iR5070 36.04","type":"Network","firstReportedAt":"2016-02-29T15:21:43.61Z","macAddress":"00-00-85-48-68-08","lastReportedAt":"2016-11-21T05:09:41Z","groupId":"2012e2d7-5723-484b-b821-4019c128aed8","status":"Ok","id":"53cf228d-c997-42d1-ab65-59876b4b4cc6","ipAddress":"192.168.2.20","modelMatch":{"modifiedAt":"2016-11-21T04:11:31.83Z","model":{"name":"Canon imageRUNNER 5070","manufacturer":"Canon","id":"be767c7a-9125-43c4-bd2e-95087fbc893d","hasImage":true,"isColor":false},"type":"AutoOne","isAutoMatchEnabled":true}}]
Resolved this. I was not serializing/deserializing the data. I have included message pack and use that to serialize/deserialize the data. Works great
Thanks