From f7e4b2f1e3d5a0e073c8bd037e5aebc9574be10e Mon Sep 17 00:00:00 2001 From: skilion Date: Tue, 22 Sep 2015 16:14:16 +0200 Subject: [PATCH] fixed acces to json nested objects --- src/onedrive.d | 2 +- src/sync.d | 17 ++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/onedrive.d b/src/onedrive.d index f7c065d6..ca30a247 100644 --- a/src/onedrive.d +++ b/src/onedrive.d @@ -72,7 +72,7 @@ final class OneDriveApi JSONValue response = get(itemByIdUrl ~ id ~ "/?select=name,parentReference"); string path; try { - path = response["parentReference"].object["path"].str; + path = response["parentReference"]["path"].str; } catch (JSONException e) { // root does not have parentReference return ""; diff --git a/src/sync.d b/src/sync.d index 12bc21e6..c516f31c 100644 --- a/src/sync.d +++ b/src/sync.d @@ -1,4 +1,3 @@ -import core.exception: RangeError; import std.exception: ErrnoException; import std.algorithm, std.datetime, std.file, std.json, std.path, std.regex; import std.stdio, std.string; @@ -109,7 +108,7 @@ final class SyncEngine { string id = item["id"].str; string name = item["name"].str; - string parentId = item["parentReference"].object["id"].str; + string parentId = item["parentReference"]["id"].str; // HACK: recognize the root directory if (name == "root" && parentId[$ - 1] == '0' && parentId[$ - 2] == '!') { @@ -174,16 +173,14 @@ final class SyncEngine string eTag = item["eTag"].str; string cTag = item["cTag"].str; - string mtime = item["fileSystemInfo"].object["lastModifiedDateTime"].str; + string mtime = item["fileSystemInfo"]["lastModifiedDateTime"].str; string crc32; if (type == ItemType.file) { try { - crc32 = item["file"].object["hashes"].object["crc32Hash"].str; + crc32 = item["file"]["hashes"]["crc32Hash"].str; } catch (JSONException e) { if (verbose) writeln("The hash is not available"); - } catch (RangeError e) { - if (verbose) writeln("The crc32 hash is not available"); } } @@ -499,16 +496,14 @@ final class SyncEngine string name = item["name"].str; string eTag = item["eTag"].str; string cTag = item["cTag"].str; - string mtime = item["fileSystemInfo"].object["lastModifiedDateTime"].str; - string parentId = item["parentReference"].object["id"].str; + string mtime = item["fileSystemInfo"]["lastModifiedDateTime"].str; + string parentId = item["parentReference"]["id"].str; string crc32; if (type == ItemType.file) { try { - crc32 = item["file"].object["hashes"].object["crc32Hash"].str; + crc32 = item["file"]["hashes"]["crc32Hash"].str; } catch (JSONException e) { // swallow exception - } catch (RangeError e) { - // swallow exception } } itemdb.upsert(id, name, type, eTag, cTag, mtime, parentId, crc32);